Distribute and handle challenge.json

This commit is contained in:
nemunaire 2022-05-01 22:33:59 +02:00
parent e8f6a03cd9
commit dff4f4eb63
20 changed files with 167 additions and 48 deletions

View file

@ -16,6 +16,9 @@ import (
var IsProductionEnv = false
func init() {
router.GET("/api/challenge.json", apiHandler(getChallengeInfo))
router.PUT("/api/challenge.json", apiHandler(saveChallengeInfo))
router.GET("/api/settings-ro.json", apiHandler(getROSettings))
router.GET("/api/settings.json", apiHandler(getSettings))
router.PUT("/api/settings.json", apiHandler(saveSettings))
@ -44,6 +47,23 @@ func getROSettings(_ httprouter.Params, body []byte) (interface{}, error) {
}, nil
}
func getChallengeInfo(_ httprouter.Params, body []byte) (interface{}, error) {
return settings.ReadChallengeInfo(path.Join(settings.SettingsDir, settings.ChallengeFile))
}
func saveChallengeInfo(_ httprouter.Params, body []byte) (interface{}, error) {
var info *settings.ChallengeInfo
if err := json.Unmarshal(body, &info); err != nil {
return nil, err
}
if err := settings.SaveChallengeInfo(path.Join(settings.SettingsDir, settings.ChallengeFile), info); err != nil {
return nil, err
} else {
return info, err
}
}
func getSettings(_ httprouter.Params, body []byte) (interface{}, error) {
if s, err := settings.ReadSettings(path.Join(settings.SettingsDir, settings.SettingsFile)); err != nil {
return nil, err
@ -83,9 +103,7 @@ func ApplySettings(config *settings.Settings) {
}
func ResetSettings() error {
return settings.SaveSettings(path.Join(settings.SettingsDir, settings.SettingsFile), &settings.FICSettings{
Title: "Challenge FIC",
Authors: "Laboratoire SRS, ÉPITA",
return settings.SaveSettings(path.Join(settings.SettingsDir, settings.SettingsFile), &settings.Settings{
WorkInProgress: IsProductionEnv,
FirstBlood: fic.FirstBlood,
SubmissionCostBase: fic.SubmissionCostBase,

View file

@ -22,8 +22,10 @@ func init() {
router.GET("/api/session-forensic.yaml", apiHandler(func(_ httprouter.Params, _ []byte) (interface{}, error) {
if s, err := settings.ReadSettings(path.Join(settings.SettingsDir, settings.SettingsFile)); err != nil {
return nil, err
} else if c, err := settings.ReadChallengeInfo(path.Join(settings.SettingsDir, settings.ChallengeFile)); err != nil {
return nil, err
} else {
return fic.GenZQDSSessionFile(s)
return fic.GenZQDSSessionFile(c, s)
}
}))
router.GET("/api/files-bindings", apiHandler(bindingFiles))

View file

@ -6,27 +6,6 @@
<input type="hidden" class="form-control form-control-sm" id="lastRegeneration" ng-model="config.generation">
<div class="form-group row">
<label for="challengeName" class="col-sm-3 col-form-label col-form-label-sm">Nom du challenge</label>
<div class="col-sm-9">
<input type="text" class="form-control form-control-sm" id="challengeName" ng-model="config.title">
</div>
</div>
<div class="form-group row">
<label for="challengeAuthors" class="col-sm-3 col-form-label col-form-label-sm">Auteurs du challenge</label>
<div class="col-sm-9">
<input type="text" class="form-control form-control-sm" id="challengeAuthors" ng-model="config.authors">
</div>
</div>
<div class="form-group row">
<label for="challengeVideo" class="col-sm-3 col-form-label col-form-label-sm">Lien vidéos de résolution</label>
<div class="col-sm-9">
<input type="text" class="form-control form-control-sm" id="challengeVideo" ng-model="config.videoslink">
</div>
</div>
<div class="form-group row">
<label for="startTime" class="col-sm-3 col-form-label col-form-label-sm">Début du challenge</label>
<div class="col-sm-9">