From 0448a2e755adeece1bc3f2c0d7497cf9aca68559 Mon Sep 17 00:00:00 2001 From: mgerb42 Date: Sun, 5 Feb 2017 06:56:40 +0000 Subject: [PATCH] adjustments to soundlist end point --- server/webserver/handlers/soundlist.go | 23 ++++++++++++++++++----- server/webserver/server.go | 1 + 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/server/webserver/handlers/soundlist.go b/server/webserver/handlers/soundlist.go index 3bf8f02..94121d4 100644 --- a/server/webserver/handlers/soundlist.go +++ b/server/webserver/handlers/soundlist.go @@ -9,7 +9,13 @@ import ( "strings" ) -var soundList = make([]string, 0) +var soundList []sound + +type sound struct { + Prefix string `json:"prefix"` + Name string `json:"name"` + Extension string `json:"extension"` +} func SoundList(ctx *fasthttp.RequestCtx) { @@ -35,9 +41,8 @@ func SoundList(ctx *fasthttp.RequestCtx) { func PopulateSoundList() error { fmt.Println("Populating sound list.") - soundList = make([]string, 0) + soundList = []sound{} - var fileName string files, err := ioutil.ReadDir(config.Config.SoundsPath) if err != nil { @@ -45,8 +50,16 @@ func PopulateSoundList() error { } for _, f := range files { - fileName = config.Config.BotPrefix + strings.Split(f.Name(), ".")[0] - soundList = append(soundList, fileName) + fileName := strings.Split(f.Name(), ".")[0] + extension := strings.Split(f.Name(), ".")[1] + + listItem := sound{ + Name: fileName, + Extension: extension, + Prefix: config.Config.BotPrefix, + } + + soundList = append(soundList, listItem) } return nil diff --git a/server/webserver/server.go b/server/webserver/server.go index 80d6d5e..5652997 100644 --- a/server/webserver/server.go +++ b/server/webserver/server.go @@ -28,6 +28,7 @@ func registerRoutes(router *fasthttprouter.Router) { router.PUT("/upload", handlers.FileUpload) router.ServeFiles("/static/*filepath", "./static") + router.ServeFiles("/sounds/*filepath", "./sounds") router.NotFound = func(ctx *fasthttp.RequestCtx) { fasthttp.ServeFile(ctx, "./index.html")