api: remote route takes advantage from builds functions
This commit is contained in:
parent
ded583008a
commit
f2fc142869
6 changed files with 83 additions and 6 deletions
|
@ -4,15 +4,17 @@ import (
|
|||
"bufio"
|
||||
"crypto"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"srs.epita.fr/fic-server/libfic"
|
||||
|
||||
"github.com/julienschmidt/httprouter"
|
||||
_ "golang.org/x/crypto/blake2b"
|
||||
|
||||
"srs.epita.fr/fic-server/libfic"
|
||||
)
|
||||
|
||||
func buildExerciceHints(i Importer, exercice fic.Exercice) (hints []fic.EHint, errs []string) {
|
||||
|
@ -106,3 +108,23 @@ func SyncExerciceHints(i Importer, exercice fic.Exercice) (errs []string) {
|
|||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ApiListRemoteExerciceHints is an accessor letting foreign packages to access remote exercice hints.
|
||||
func ApiGetRemoteExerciceHints(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 {
|
||||
hints, errs := CheckExerciceHints(GlobalImporter, *exercice)
|
||||
if hints != nil {
|
||||
return hints, nil
|
||||
} else {
|
||||
return hints, errors.New(fmt.Sprintf("%q", errs))
|
||||
}
|
||||
} else {
|
||||
return exercice, errors.New(fmt.Sprintf("%q", errs))
|
||||
}
|
||||
} else {
|
||||
return nil, errors.New(fmt.Sprintf("%q", errs))
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue