api: remote route takes advantage from builds functions

This commit is contained in:
nemunaire 2019-09-07 01:25:42 +02:00
commit f2fc142869
6 changed files with 83 additions and 6 deletions

View file

@ -1,6 +1,7 @@
package sync
import (
"errors"
"fmt"
"math/rand"
"path"
@ -8,6 +9,8 @@ import (
"strings"
"unicode"
"github.com/julienschmidt/httprouter"
"srs.epita.fr/fic-server/libfic"
)
@ -385,3 +388,23 @@ func SyncExerciceFlags(i Importer, exercice fic.Exercice) (errs []string) {
return
}
// ApiListRemoteExerciceFlags is an accessor letting foreign packages to access remote exercice flags.
func ApiGetRemoteExerciceFlags(ps httprouter.Params, _ []byte) (interface{}, error) {
theme, errs := BuildTheme(GlobalImporter, ps.ByName("thid"))
if theme != nil {
exercice, _, _, _, errs := BuildExercice(GlobalImporter, *theme, path.Join(theme.Path, ps.ByName("exid")), nil)
if exercice != nil {
flags, errs := CheckExerciceFlags(GlobalImporter, *exercice, []fic.EFile{})
if flags != nil {
return flags, nil
} else {
return flags, errors.New(fmt.Sprintf("%q", errs))
}
} else {
return exercice, errors.New(fmt.Sprintf("%q", errs))
}
} else {
return nil, errors.New(fmt.Sprintf("%q", errs))
}
}