Handle file import digest
This commit is contained in:
parent
0b4e8a233c
commit
1bd403cd8c
4 changed files with 43 additions and 10 deletions
|
@ -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 <<EOF >&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" <<EOF | grep -Eo '"id":[0-9]+,' | grep -Eo "[0-9]+"
|
||||
{"path": "${BASEFILE}${URI}", "parts": [${PARTS}]}
|
||||
{"path": "${BASEFILE}${URI}"${DIGEST}, "parts": [${PARTS}]}
|
||||
EOF
|
||||
)
|
||||
|
||||
|
@ -192,6 +199,8 @@ do
|
|||
# Files: splited
|
||||
get_dir "${THM_BASEURI}${EXO_BASEURI}files/" | grep -v DIGESTS.txt | grep '[0-9][0-9]$' | sed -E 's/\.?([0-9][0-9])$//' | sort | uniq | while read f; do basename "$f"; done | while read FILE_URI
|
||||
do
|
||||
DIGEST=$(get_file "${THM_BASEURI}${EXO_BASEURI}files/DIGESTS.txt" | grep "${FILE_URI}\$" | awk '{ print $1; }')
|
||||
|
||||
PARTS=
|
||||
for part in $(get_dir "${THM_BASEURI}${EXO_BASEURI}files/" | grep "${FILE_URI}" | sort)
|
||||
do
|
||||
|
@ -200,7 +209,7 @@ do
|
|||
done
|
||||
echo -e "\e[35mImport splited file ${THM_BASEURI}${EXO_BASEURI}files/${FILE_URI} from\e[00m `echo ${PARTS} | tr '\n' ' '`"
|
||||
|
||||
FILE_ID=`new_file "${THEME_ID}" "${EXO_ID}" "${THM_BASEURI}${EXO_BASEURI}files/${FILE_URI}" "${PARTS}"`
|
||||
FILE_ID=`new_file "${THEME_ID}" "${EXO_ID}" "${THM_BASEURI}${EXO_BASEURI}files/${FILE_URI}" "${DIGEST}" "${PARTS}"`
|
||||
if [ -z "$FILE_ID" ]; then
|
||||
echo -e "\e[31;01m!!! An error occured during file import! Please check path.\e[00m"
|
||||
else
|
||||
|
@ -211,8 +220,10 @@ do
|
|||
# Files: entire
|
||||
get_dir "${THM_BASEURI}${EXO_BASEURI}files/" | grep -v DIGESTS.txt | grep -v '[0-9][0-9]$' | while read f; do basename "$f"; done | while read FILE_URI
|
||||
do
|
||||
DIGEST=$(get_file "${THM_BASEURI}${EXO_BASEURI}files/DIGESTS.txt" | grep "${FILE_URI}\$" | awk '{ print $1; }')
|
||||
|
||||
echo "Import file ${THM_BASEURI}${EXO_BASEURI}files/${FILE_URI}"
|
||||
FILE_ID=`new_file "${THEME_ID}" "${EXO_ID}" "${THM_BASEURI}${EXO_BASEURI}files/${FILE_URI}"`
|
||||
FILE_ID=`new_file "${THEME_ID}" "${EXO_ID}" "${THM_BASEURI}${EXO_BASEURI}files/${FILE_URI}" "${DIGEST}"`
|
||||
if [ -z "$FILE_ID" ]; then
|
||||
echo -e "\e[31;01m!!! An error occured during file import! Please check path.\e[00m"
|
||||
else
|
||||
|
|
Reference in a new issue