Hints can something else than text
This commit is contained in:
parent
8c2e8a19d1
commit
b772a22705
6 changed files with 69 additions and 25 deletions
|
@ -5,7 +5,6 @@ import (
|
|||
"crypto/sha512"
|
||||
"encoding/base32"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
|
@ -29,12 +28,7 @@ type uploadedFile struct {
|
|||
Parts []string
|
||||
}
|
||||
|
||||
func createExerciceFile(exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
var uf uploadedFile
|
||||
if err := json.Unmarshal(body, &uf); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func importFile(uf uploadedFile, next func(string, string, []byte) (interface{}, error)) (interface{}, error) {
|
||||
var hash [sha512.Size]byte
|
||||
var logStr string
|
||||
var fromURI string
|
||||
|
@ -80,7 +74,7 @@ func createExerciceFile(exercice fic.Exercice, body []byte) (interface{}, error)
|
|||
pathname := path.Join(fic.FilesDir, strings.ToLower(base32.StdEncoding.EncodeToString(hash[:])), path.Base(fromURI))
|
||||
|
||||
// Remove the file if it exists
|
||||
if _, err := os.Stat(pathname); os.IsExist(err) && !RapidImport {
|
||||
if _, err := os.Stat(pathname); !os.IsNotExist(err) && !RapidImport {
|
||||
if err := os.Remove(pathname); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -98,7 +92,7 @@ func createExerciceFile(exercice fic.Exercice, body []byte) (interface{}, error)
|
|||
if digest, err := hex.DecodeString(uf.Digest); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return exercice.ImportFile(pathname, fromURI, digest)
|
||||
return next(pathname, fromURI, digest)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue