Hints can something else than text
This commit is contained in:
parent
ee8bb97057
commit
c2dea2f985
6 changed files with 69 additions and 25 deletions
|
|
@ -3,6 +3,7 @@ package api
|
|||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"srs.epita.fr/fic-server/libfic"
|
||||
|
||||
|
|
@ -119,17 +120,29 @@ func createExerciceKey(exercice fic.Exercice, body []byte) (interface{}, error)
|
|||
return exercice.AddRawKey(uk.Type, uk.Key)
|
||||
}
|
||||
|
||||
type uploadedHint struct {
|
||||
Title string
|
||||
Content string
|
||||
Cost int64
|
||||
Path string
|
||||
}
|
||||
|
||||
func createExerciceHint(exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
var uh fic.EHint
|
||||
var uh uploadedHint
|
||||
if err := json.Unmarshal(body, &uh); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(uh.Content) == 0 {
|
||||
if len(uh.Content) != 0 {
|
||||
return exercice.AddHint(uh.Title, uh.Content, uh.Cost)
|
||||
} else if len(uh.Path) != 0 {
|
||||
return importFile(uploadedFile{Path: uh.Path},
|
||||
func(filePath string, origin string, digest []byte) (interface{}, error) {
|
||||
return exercice.AddHint(uh.Title, "$FILES" + strings.TrimPrefix(filePath, fic.FilesDir), uh.Cost)
|
||||
})
|
||||
} else {
|
||||
return nil, errors.New("Hint's content not filled")
|
||||
}
|
||||
|
||||
return exercice.AddHint(uh.Title, uh.Content, uh.Cost)
|
||||
}
|
||||
|
||||
func showExerciceHint(hint fic.EHint, body []byte) (interface{}, error) {
|
||||
|
|
@ -189,6 +202,15 @@ func deleteExerciceKey(key fic.Key, _ fic.Exercice, _ []byte) (interface{}, erro
|
|||
}
|
||||
|
||||
|
||||
func createExerciceFile(exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
var uf uploadedFile
|
||||
if err := json.Unmarshal(body, &uf); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return importFile(uf, exercice.ImportFile)
|
||||
}
|
||||
|
||||
func showExerciceFile(file fic.EFile, body []byte) (interface{}, error) {
|
||||
return file, nil
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue