Can upload new gong

This commit is contained in:
nemunaire 2022-10-15 12:26:05 +02:00
commit cc301da971
4 changed files with 121 additions and 4 deletions

View file

@ -23,6 +23,23 @@ func CurrentGongPath(cfg *config.Config) string {
return filepath.Join(cfg.GongsDir, CURRENT_GONG)
}
func LoadGong(cfg *config.Config, path string, d fs.FileInfo) (gong *Gong, err error) {
// Retrieve the path of the current gong
current_gong, err := os.Readlink(CurrentGongPath(cfg))
if err == nil {
current_gong, _ = filepath.Abs(filepath.Join(cfg.GongsDir, current_gong))
}
hash := sha512.Sum512([]byte(path))
pabs, _ := filepath.Abs(path)
return &Gong{
Id: hash[:],
Name: strings.TrimSuffix(d.Name(), filepath.Ext(d.Name())),
Path: path,
Enabled: current_gong == pabs,
}, nil
}
func LoadGongs(cfg *config.Config) (gongs []*Gong, err error) {
// Retrieve the path of the current gong
current_gong, err := os.Readlink(CurrentGongPath(cfg))