sync: return binding between challenge.txt IDs and DB item
This commit is contained in:
parent
4a490b1a33
commit
d97ecde3fb
5 changed files with 20 additions and 10 deletions
|
@ -65,11 +65,13 @@ func init() {
|
||||||
})))
|
})))
|
||||||
router.POST("/api/sync/exercices/:eid/hints", apiHandler(exerciceHandler(
|
router.POST("/api/sync/exercices/:eid/hints", apiHandler(exerciceHandler(
|
||||||
func(exercice fic.Exercice, _ []byte) (interface{}, error) {
|
func(exercice fic.Exercice, _ []byte) (interface{}, error) {
|
||||||
return sync.SyncExerciceHints(sync.GlobalImporter, exercice), nil
|
_, errs := sync.SyncExerciceHints(sync.GlobalImporter, exercice)
|
||||||
|
return errs, nil
|
||||||
})))
|
})))
|
||||||
router.POST("/api/sync/exercices/:eid/flags", apiHandler(exerciceHandler(
|
router.POST("/api/sync/exercices/:eid/flags", apiHandler(exerciceHandler(
|
||||||
func(exercice fic.Exercice, _ []byte) (interface{}, error) {
|
func(exercice fic.Exercice, _ []byte) (interface{}, error) {
|
||||||
return sync.SyncExerciceFlags(sync.GlobalImporter, exercice), nil
|
_, errs := sync.SyncExerciceFlags(sync.GlobalImporter, exercice)
|
||||||
|
return errs, nil
|
||||||
})))
|
})))
|
||||||
|
|
||||||
router.POST("/api/sync/exercices/:eid/fixurlid", apiHandler(exerciceHandler(
|
router.POST("/api/sync/exercices/:eid/fixurlid", apiHandler(exerciceHandler(
|
||||||
|
|
|
@ -70,11 +70,13 @@ func init() {
|
||||||
})))
|
})))
|
||||||
router.POST("/api/sync/themes/:thid/exercices/:eid/hints", apiHandler(exerciceHandler(
|
router.POST("/api/sync/themes/:thid/exercices/:eid/hints", apiHandler(exerciceHandler(
|
||||||
func(exercice fic.Exercice, _ []byte) (interface{}, error) {
|
func(exercice fic.Exercice, _ []byte) (interface{}, error) {
|
||||||
return sync.SyncExerciceHints(sync.GlobalImporter, exercice), nil
|
_, errs := sync.SyncExerciceHints(sync.GlobalImporter, exercice)
|
||||||
|
return errs, nil
|
||||||
})))
|
})))
|
||||||
router.POST("/api/sync/themes/:thid/exercices/:eid/keys", apiHandler(exerciceHandler(
|
router.POST("/api/sync/themes/:thid/exercices/:eid/keys", apiHandler(exerciceHandler(
|
||||||
func(exercice fic.Exercice, _ []byte) (interface{}, error) {
|
func(exercice fic.Exercice, _ []byte) (interface{}, error) {
|
||||||
return sync.SyncExerciceFlags(sync.GlobalImporter, exercice), nil
|
_, errs := sync.SyncExerciceFlags(sync.GlobalImporter, exercice)
|
||||||
|
return errs, nil
|
||||||
})))
|
})))
|
||||||
|
|
||||||
router.POST("/api/sync/themes/:thid/fixurlid", apiHandler(themeHandler(
|
router.POST("/api/sync/themes/:thid/fixurlid", apiHandler(themeHandler(
|
||||||
|
|
|
@ -92,7 +92,7 @@ func CheckExerciceHints(i Importer, exercice fic.Exercice) ([]fic.EHint, []strin
|
||||||
}
|
}
|
||||||
|
|
||||||
// SyncExerciceHints reads the content of hints/ directories and import it as EHint for the given challenge.
|
// SyncExerciceHints reads the content of hints/ directories and import it as EHint for the given challenge.
|
||||||
func SyncExerciceHints(i Importer, exercice fic.Exercice) (errs []string) {
|
func SyncExerciceHints(i Importer, exercice fic.Exercice) (hintsBindings map[int]fic.EHint, errs []string) {
|
||||||
if _, err := exercice.WipeHints(); err != nil {
|
if _, err := exercice.WipeHints(); err != nil {
|
||||||
errs = append(errs, err.Error())
|
errs = append(errs, err.Error())
|
||||||
} else {
|
} else {
|
||||||
|
@ -101,8 +101,10 @@ func SyncExerciceHints(i Importer, exercice fic.Exercice) (errs []string) {
|
||||||
|
|
||||||
for n, hint := range hints {
|
for n, hint := range hints {
|
||||||
// Import hint
|
// Import hint
|
||||||
if _, err := exercice.AddHint(hint.Title, hint.Content, hint.Cost); err != nil {
|
if h, err := exercice.AddHint(hint.Title, hint.Content, hint.Cost); err != nil {
|
||||||
errs = append(errs, fmt.Sprintf("%q: hint #%d %s: %s", path.Base(exercice.Path), n+1, hint.Title, err))
|
errs = append(errs, fmt.Sprintf("%q: hint #%d %s: %s", path.Base(exercice.Path), n+1, hint.Title, err))
|
||||||
|
} else {
|
||||||
|
hintsBindings[n+1] = h
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -347,7 +347,7 @@ func CheckExerciceFlags(i Importer, exercice fic.Exercice, files []fic.EFile) (r
|
||||||
}
|
}
|
||||||
|
|
||||||
// SyncExerciceFlags imports all kind of flags for the given challenge.
|
// SyncExerciceFlags imports all kind of flags for the given challenge.
|
||||||
func SyncExerciceFlags(i Importer, exercice fic.Exercice) (errs []string) {
|
func SyncExerciceFlags(i Importer, exercice fic.Exercice) (kmap map[int64]fic.Flag, errs []string) {
|
||||||
if _, err := exercice.WipeFlags(); err != nil {
|
if _, err := exercice.WipeFlags(); err != nil {
|
||||||
errs = append(errs, err.Error())
|
errs = append(errs, err.Error())
|
||||||
} else if _, err := exercice.WipeMCQs(); err != nil {
|
} else if _, err := exercice.WipeMCQs(); err != nil {
|
||||||
|
@ -356,7 +356,7 @@ func SyncExerciceFlags(i Importer, exercice fic.Exercice) (errs []string) {
|
||||||
flags, flagids, berrs := buildExerciceFlags(i, exercice)
|
flags, flagids, berrs := buildExerciceFlags(i, exercice)
|
||||||
errs = append(errs, berrs...)
|
errs = append(errs, berrs...)
|
||||||
|
|
||||||
kmap := map[int64]fic.Flag{}
|
kmap = map[int64]fic.Flag{}
|
||||||
|
|
||||||
// Import flags
|
// Import flags
|
||||||
for _, flagid := range flagids {
|
for _, flagid := range flagids {
|
||||||
|
|
|
@ -45,10 +45,14 @@ func SyncDeep(i Importer) (errs map[string][]string) {
|
||||||
for eid, exercice := range exercices {
|
for eid, exercice := range exercices {
|
||||||
DeepSyncProgress = 3 + uint8(tid) * themeStep + uint8(eid) * exerciceStep
|
DeepSyncProgress = 3 + uint8(tid) * themeStep + uint8(eid) * exerciceStep
|
||||||
errs[theme.Name] = append(errs[theme.Name], SyncExerciceFiles(i, exercice)...)
|
errs[theme.Name] = append(errs[theme.Name], SyncExerciceFiles(i, exercice)...)
|
||||||
|
|
||||||
DeepSyncProgress += exerciceStep / 3
|
DeepSyncProgress += exerciceStep / 3
|
||||||
errs[theme.Name] = append(errs[theme.Name], SyncExerciceFlags(i, exercice)...)
|
_, ferrs := SyncExerciceFlags(i, exercice)
|
||||||
|
errs[theme.Name] = append(errs[theme.Name], ferrs...)
|
||||||
|
|
||||||
DeepSyncProgress += exerciceStep / 3
|
DeepSyncProgress += exerciceStep / 3
|
||||||
errs[theme.Name] = append(errs[theme.Name], SyncExerciceHints(i, exercice)...)
|
_, herrs := SyncExerciceHints(i, exercice)
|
||||||
|
errs[theme.Name] = append(errs[theme.Name], herrs...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue