From 1bd403cd8c8486909d0df0035c5c483fe7c0aea4 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Wed, 4 Jan 2017 01:30:24 +0100 Subject: [PATCH] Handle file import digest --- admin/api/file.go | 9 +++++++-- admin/fill_exercices.sh | 19 +++++++++++++++---- admin/main.go | 1 + libfic/file.go | 24 ++++++++++++++++++++---- 4 files changed, 43 insertions(+), 10 deletions(-) diff --git a/admin/api/file.go b/admin/api/file.go index bee0fc97..e8667107 100644 --- a/admin/api/file.go +++ b/admin/api/file.go @@ -4,6 +4,7 @@ import ( "bufio" "crypto/sha512" "encoding/base32" + "encoding/hex" "encoding/json" "errors" "fmt" @@ -23,7 +24,7 @@ var RapidImport bool type uploadedFile struct { URI string - Digest []byte + Digest string Path string Parts []string } @@ -94,7 +95,11 @@ func createExerciceFile(exercice fic.Exercice, body []byte) (interface{}, error) } } - return exercice.ImportFile(pathname, fromURI) + if digest, err := hex.DecodeString(uf.Digest); err != nil { + return nil, err + } else { + return exercice.ImportFile(pathname, fromURI, digest) + } } func getCloudFile(pathname string, dest string) error { diff --git a/admin/fill_exercices.sh b/admin/fill_exercices.sh index 2169bf5a..e97837ce 100755 --- a/admin/fill_exercices.sh +++ b/admin/fill_exercices.sh @@ -28,7 +28,8 @@ new_file() ( THEME="$1" EXERCICE="$2" URI="$3" - ARGS="$4" + DIGEST="$4" + ARGS="$5" FIRST= PARTS=$(echo "$ARGS" | while read arg @@ -40,9 +41,15 @@ new_file() ( FIRST=1 done) + [ -n "${DIGEST}" ] && DIGEST=", \"digest\": \"${DIGEST}\"" + + cat <&2 +{"path": "${BASEFILE}${URI}"${DIGEST}, "parts": [${PARTS}]} +EOF + # curl -f -s -d "{\"URI\": \"${BASEFILE}${URI}\"}" "${BASEURL}/api/themes/$THEME/$EXERCICE/files" | curl -f -s -d @- "${BASEURL}/api/themes/$THEME/exercices/$EXERCICE/files" <