admin/api: new route to list remote files and their properties
This commit is contained in:
parent
084d39f6cf
commit
2bae30a841
@ -29,6 +29,9 @@ func init() {
|
||||
router.PUT("/api/exercices/:eid/files/:fid", apiHandler(exerciceFileHandler(updateFile)))
|
||||
router.DELETE("/api/exercices/:eid/files/:fid", apiHandler(exerciceFileHandler(deleteFile)))
|
||||
|
||||
// Remote
|
||||
router.GET("/api/remote/themes/:thid/exercices/:exid/files", apiHandler(sync.ApiGetRemoteExerciceFiles))
|
||||
|
||||
// Check
|
||||
router.POST("/api/files/:fileid/check", apiHandler(fileHandler(checkFile)))
|
||||
|
||||
|
@ -3,11 +3,14 @@ package sync
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"path"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"github.com/julienschmidt/httprouter"
|
||||
|
||||
"srs.epita.fr/fic-server/libfic"
|
||||
)
|
||||
|
||||
@ -137,3 +140,34 @@ func SyncExerciceFiles(i Importer, exercice fic.Exercice) (errs []string) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ApiGetRemoteExerciceFiles is an accessor to remote exercice files list.
|
||||
func ApiGetRemoteExerciceFiles(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 {
|
||||
files, digests, errs := BuildFilesListInto(GlobalImporter, *exercice, "files")
|
||||
if files != nil {
|
||||
var ret []fic.EFile
|
||||
for _, fname := range files {
|
||||
fPath := path.Join(exercice.Path, "files", fname)
|
||||
fSize, _ := getFileSize(GlobalImporter, fPath)
|
||||
ret = append(ret, fic.EFile{
|
||||
Path: fPath,
|
||||
Name: fname,
|
||||
Checksum: digests[fname],
|
||||
Size: fSize,
|
||||
})
|
||||
}
|
||||
return ret, nil
|
||||
} else {
|
||||
return nil, errors.New(fmt.Sprintf("%q", errs))
|
||||
}
|
||||
} else {
|
||||
return nil, errors.New(fmt.Sprintf("%q", errs))
|
||||
}
|
||||
} else {
|
||||
return nil, errors.New(fmt.Sprintf("%q", errs))
|
||||
}
|
||||
}
|
||||
|
@ -29,13 +29,13 @@ var PlainDigest bool = false
|
||||
|
||||
// EFile represents a challenge file.
|
||||
type EFile struct {
|
||||
Id int64 `json:"id"`
|
||||
Id int64 `json:"id,omitempty"`
|
||||
// origin holds the import relative path of the file
|
||||
origin string
|
||||
// Path is the location where the file is stored, relatively to FilesDir
|
||||
Path string `json:"path"`
|
||||
// IdExercice is the identifier of the underlying challenge
|
||||
IdExercice int64 `json:"idExercice"`
|
||||
IdExercice int64 `json:"idExercice,omitempty"`
|
||||
// Name is the title displayed to players
|
||||
Name string `json:"name"`
|
||||
// Checksum stores the cached hash of the file
|
||||
|
Loading…
Reference in New Issue
Block a user