Files
MusicServer/internal/backend/characters.go
T
Sansan 8f8b555ea5
Build / build (push) Successful in 48s
Refactor handlers and update changelog for 5.0.0-Beta
- Split IndexHandler into HealthHandler, VersionHandler, and CharacterHandler
- Rename index.go to version.go in backend
- Change VersionData.Changelog from string to []string
- Add changelog entries for issues #16-#23
- Remove TestDB function and related code
- Fix import ordering in several files

Closes #21, #22
References #16, #17, #18, #19, #20, #23

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-06-08 20:08:06 +02:00

44 lines
1.4 KiB
Go

package backend
import (
"os"
"strings"
"go.uber.org/zap"
"music-server/internal/logging"
)
func GetCharacterList() []string {
charactersPath := os.Getenv("CHARACTERS_PATH")
logging.GetLogger().Debug("Getting character list", zap.String("path", charactersPath))
// Clean the path - remove trailing slashes and then add one for consistency
charactersPath = strings.TrimSuffix(charactersPath, "/")
charactersPath += "/"
files, err := os.ReadDir(charactersPath)
if err != nil {
logging.GetLogger().Fatal("Failed to read characters directory", zap.String("path", charactersPath), zap.String("error", err.Error()))
}
var characters []string
for _, file := range files {
if isImage(file) {
characters = append(characters, file.Name())
}
}
return characters
}
func GetCharacter(character string) string {
charactersPath := os.Getenv("CHARACTERS_PATH")
// Clean the path - remove trailing slashes and then add one for consistency
charactersPath = strings.TrimSuffix(charactersPath, "/")
charactersPath += "/"
logging.GetLogger().Debug("Getting character", zap.String("character", character), zap.String("path", charactersPath+character))
return charactersPath + character
}
func isImage(entry os.DirEntry) bool {
return !entry.IsDir() && (strings.HasSuffix(entry.Name(), ".jpg") || strings.HasSuffix(entry.Name(), ".jpeg") ||
strings.HasSuffix(entry.Name(), ".png"))
}