admin/api: new route to list remote files and their properties
This commit is contained in:
parent
084d39f6cf
commit
2bae30a841
3 changed files with 39 additions and 2 deletions
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue