server/admin/sync/challengeinfo.go

47 lines
1.1 KiB
Go
Raw Normal View History

2022-06-06 18:42:46 +00:00
package sync
import (
"path"
"strings"
"srs.epita.fr/fic-server/libfic"
"srs.epita.fr/fic-server/settings"
)
// ImportChallengeInfo imports images defined in the challengeinfo.
func ImportChallengeInfo(ci *settings.ChallengeInfo, dashboardDir string) (err error) {
2022-06-06 18:42:46 +00:00
if len(ci.MainLogo) > 0 {
for i, logo := range ci.MainLogo {
dest := path.Join(fic.FilesDir, "logo", path.Base(logo))
err = importFile(GlobalImporter, logo, dest)
if err != nil {
return
}
ci.MainLogo[i] = path.Join("$FILES$", strings.TrimPrefix(dest, fic.FilesDir))
}
}
if len(ci.DashboardBackground) > 0 {
dest := path.Join(dashboardDir, path.Base(ci.DashboardBackground))
err = importFile(GlobalImporter, ci.DashboardBackground, dest)
if err != nil {
return
}
}
2022-06-06 18:42:46 +00:00
if len(ci.Partners) > 0 {
for i, partner := range ci.Partners {
dest := path.Join(fic.FilesDir, "partner", path.Base(partner.Src))
err = importFile(GlobalImporter, partner.Src, dest)
if err != nil {
return
}
ci.Partners[i].Src = path.Join("$FILES$", strings.TrimPrefix(dest, fic.FilesDir))
}
}
return nil
}