From 525070fe23cfd4ec3e51f1f7afd0b5295aee846e Mon Sep 17 00:00:00 2001 From: Ville Rantanen Date: Sat, 24 Feb 2018 09:40:20 +0200 Subject: [PATCH] tuning splitter --- code/app.py | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/code/app.py b/code/app.py index f946300..b4e3a27 100644 --- a/code/app.py +++ b/code/app.py @@ -134,7 +134,7 @@ def upload_join_splitted(name, password): for part in range(100): filename = os.path.join( share['path'], - "%s.part.%02d"%( + "%s.part.%03d"%( request.form['filename'], part ) @@ -456,35 +456,38 @@ def script_upload_split(name = None, password = None): return "Upload not allowed",400 return """#!/bin/bash test -n "$1" || { - echo "First argument is split size in megabytes, add files to upload as next arguments" - exit 1 -} -test -n "$2" || { - echo "Add files to upload as argument" + echo "Usage: [-s SplitMegabytes] file/folder [files/folders]" exit 1 } +MAXBYTES=$(( 512 * 1024 * 1024 )) +for (( i=1; i<=$#; i++ )); do + j=$(( $i + 1 )) + [[ ${!i} = "-s" ]] && { + MAXBYTES=$(( ${!j} * 1024 * 1024 )) + shift 2 + } +done CAT=$( which cat ) which pv &> /dev/null && CAT=$( which pv ) ROOTURL="%s" SHARE="%s" TOKEN="%s" -MAXBYTES=$(( $1 * 1024 * 1024 )) -shift 1 send_file() { - $CAT "$file_name" | split -d -b $MAXBYTES \ - --filter="curl -F \\"file=@-;filename=\${FILE}\\" ${ROOTURL}upload/${SHARE}/${TOKEN}" \ - - "$base_name.part." - curl -F "filename=$base_name" ${ROOTURL}upload_join/${SHARE}/${TOKEN} + $CAT "$file_name" | split -d -a 3 -b $MAXBYTES \ + --filter="curl -f -F \\"file=@-;filename=\${FILE}\\" ${ROOTURL}upload/${SHARE}/${TOKEN}" \ + - "$base_name.part." && \ + curl -F "filename=$base_name" ${ROOTURL}upload_join/${SHARE}/${TOKEN} } send_folder() { which pv &> /dev/null && printf -v dusize -- "--size %%dk" $( du -s -k "$file_name" | cut -f1 ) - tar c "$file_name" | $CAT $dusize - | split -d -b $MAXBYTES \ - --filter="curl -F \\"file=@-;filename=\${FILE}\\" ${ROOTURL}upload/${SHARE}/${TOKEN}" \ - - "$base_name.tgz.part." - curl -F "filename=$base_name.tgz" ${ROOTURL}upload_join/${SHARE}/${TOKEN} + tar c "$file_name" | $CAT $dusize - | split -d -a 3 -b $MAXBYTES \ + --filter="curl -f -F \\"file=@-;filename=\${FILE}\\" ${ROOTURL}upload/${SHARE}/${TOKEN}" \ + - "$base_name.tar.part." && \ + curl -F "filename=$base_name.tar" ${ROOTURL}upload_join/${SHARE}/${TOKEN} } +echo "Splitting to $(( $MAXBYTES / 1024 / 1024 )) Mb chunks" for file_name in "$@"; do base_name=$( basename "$file_name" ) test -f "$file_name" && {