admin: Implement sychronization backends
We are now able, depending on configuration, to retrieve files from either WebDAV or local file system.
This commit is contained in:
parent
6237f7755a
commit
8f7de926d3
7 changed files with 281 additions and 160 deletions
|
|
@ -2,10 +2,12 @@ package api
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"srs.epita.fr/fic-server/libfic"
|
||||
"srs.epita.fr/fic-server/admin/sync"
|
||||
|
||||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
|
|
@ -125,7 +127,6 @@ type uploadedHint struct {
|
|||
Content string
|
||||
Cost int64
|
||||
URI string
|
||||
Path string
|
||||
}
|
||||
|
||||
func createExerciceHint(exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
|
|
@ -136,9 +137,9 @@ func createExerciceHint(exercice fic.Exercice, body []byte) (interface{}, error)
|
|||
|
||||
if len(uh.Content) != 0 {
|
||||
return exercice.AddHint(uh.Title, uh.Content, uh.Cost)
|
||||
} else if len(uh.Path) != 0 || len(uh.URI) != 0 {
|
||||
return importFile(uploadedFile{Path: uh.Path, URI: uh.URI},
|
||||
func(filePath string, origin string, digest []byte) (interface{}, error) {
|
||||
} else if len(uh.URI) != 0 {
|
||||
return sync.ImportFile(uh.URI,
|
||||
func(filePath string, origin string) (interface{}, error) {
|
||||
return exercice.AddHint(uh.Title, "$FILES" + strings.TrimPrefix(filePath, fic.FilesDir), uh.Cost)
|
||||
})
|
||||
} else {
|
||||
|
|
@ -209,7 +210,14 @@ func createExerciceFile(exercice fic.Exercice, body []byte) (interface{}, error)
|
|||
return nil, err
|
||||
}
|
||||
|
||||
return importFile(uf, exercice.ImportFile)
|
||||
return sync.ImportFile(uf.URI,
|
||||
func(filePath string, origin string) (interface{}, error) {
|
||||
if digest, err := hex.DecodeString(uf.Digest); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return exercice.ImportFile(filePath, origin, digest)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func showExerciceFile(file fic.EFile, body []byte) (interface{}, error) {
|
||||
|
|
|
|||
Reference in a new issue