Added support for fetching character images from the server
This commit is contained in:
35
internal/backend/charecters.go
Normal file
35
internal/backend/charecters.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package backend
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func GetCharacters() []string {
|
||||
musicPath := os.Getenv("MUSIC_PATH")
|
||||
charactersPath := musicPath + "characters/"
|
||||
files, err := os.ReadDir(charactersPath)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var characters []string
|
||||
for _, file := range files {
|
||||
if isImage(file) {
|
||||
characters = append(characters, file.Name())
|
||||
}
|
||||
}
|
||||
return characters
|
||||
}
|
||||
|
||||
func GetCharacter(character string) string {
|
||||
musicPath := os.Getenv("MUSIC_PATH")
|
||||
charactersPath := musicPath + "characters/"
|
||||
return charactersPath + character
|
||||
}
|
||||
|
||||
func isImage(entry os.DirEntry) bool {
|
||||
return !entry.IsDir() && (strings.HasSuffix(entry.Name(), ".jpg") || strings.HasSuffix(entry.Name(), ".png"))
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ func SyncGames() {
|
||||
dir = "/Users/sebastian/ResilioSync/Sorterat_test/"
|
||||
}
|
||||
fmt.Printf("dir: %s\n", dir)
|
||||
foldersToSkip := []string{".sync", "dist", "old"}
|
||||
foldersToSkip := []string{".sync", "dist", "old", "characters"}
|
||||
fmt.Println(foldersToSkip)
|
||||
db.SetGameDeletionDate()
|
||||
checkBrokenSongs()
|
||||
@@ -107,7 +107,7 @@ func SyncGamesQuick() {
|
||||
dir = "/Users/sebastian/ResilioSync/Sorterat_test/"
|
||||
}
|
||||
fmt.Printf("dir: %s\n", dir)
|
||||
foldersToSkip := []string{".sync", "dist", "old"}
|
||||
foldersToSkip := []string{".sync", "dist", "old", "characters"}
|
||||
fmt.Println(foldersToSkip)
|
||||
db.SetGameDeletionDate()
|
||||
checkBrokenSongs()
|
||||
@@ -273,7 +273,7 @@ func syncGamesNew(full bool) Response {
|
||||
fmt.Printf("dir: %s\n", musicPath)
|
||||
repo = repository.New(db.Dbpool)
|
||||
start := time.Now()
|
||||
foldersToSkip := []string{".sync", "dist", "old"}
|
||||
foldersToSkip := []string{".sync", "dist", "old", "characters"}
|
||||
fmt.Println(foldersToSkip)
|
||||
|
||||
var err error
|
||||
|
||||
@@ -26,3 +26,13 @@ func (i *IndexHandler) GetDBTest(ctx echo.Context) error {
|
||||
backend.TestDB()
|
||||
return ctx.JSON(http.StatusOK, "TestedDB")
|
||||
}
|
||||
|
||||
func (i *IndexHandler) GetCharacters(ctx echo.Context) error {
|
||||
characters := backend.GetCharacters()
|
||||
return ctx.JSON(http.StatusOK, characters)
|
||||
}
|
||||
|
||||
func (i *IndexHandler) GetCharacter(ctx echo.Context) error {
|
||||
character := ctx.QueryParam("character")
|
||||
return ctx.File(backend.GetCharacter(character))
|
||||
}
|
||||
|
||||
@@ -39,6 +39,8 @@ func (s *Server) RegisterRoutes() http.Handler {
|
||||
index := NewIndexHandler()
|
||||
e.GET("/version", index.GetVersion)
|
||||
e.GET("/health", index.GetDBTest)
|
||||
e.GET("/character", index.GetCharacter)
|
||||
e.GET("/characters", index.GetCharacters)
|
||||
|
||||
sync := NewSyncHandler()
|
||||
syncGroup := e.Group("/sync")
|
||||
|
||||
Reference in New Issue
Block a user