Can upload new track

This commit is contained in:
nemunaire 2022-10-15 12:20:18 +02:00
commit 192ff6c4e1
4 changed files with 114 additions and 4 deletions

View file

@ -18,6 +18,16 @@ type Track struct {
Enabled bool `json:"enabled"`
}
func LoadTrack(path string, d fs.FileInfo) (track *Track, err error) {
hash := sha512.Sum512([]byte(path))
return &Track{
Id: hash[:],
Name: strings.TrimSuffix(d.Name(), filepath.Ext(d.Name())),
Path: path,
Enabled: len(strings.Split(path, "/")) == 2,
}, nil
}
func LoadTracks(cfg *config.Config) (tracks []*Track, err error) {
err = filepath.Walk(cfg.TracksDir, func(path string, d fs.FileInfo, err error) error {
if d.Mode().IsRegular() {