upload script for folders
This commit is contained in:
29
code/app.py
29
code/app.py
@@ -11,7 +11,7 @@ import hashlib
|
||||
import zipfile
|
||||
from revprox import ReverseProxied
|
||||
|
||||
__FLEES_VERSION__ = "20180219.0"
|
||||
__FLEES_VERSION__ = "20180220.0"
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(__name__)
|
||||
# Read config from json !
|
||||
@@ -248,21 +248,36 @@ def script_upload(name = None, password = None):
|
||||
if not get_or_none(share,'upload') == True:
|
||||
return "Upload not allowed",400
|
||||
return """#!/bin/bash
|
||||
test -f "$1" || {
|
||||
test -n "$1" || {
|
||||
echo "Add files to upload as argument"
|
||||
exit 1
|
||||
}
|
||||
CAT=$( which cat )
|
||||
which pv &> /dev/null && CAT=$( which pv )
|
||||
ROOTURL="%s"
|
||||
SHARE="%s"
|
||||
TOKEN="%s"
|
||||
|
||||
send_file() {
|
||||
$CAT "$file_name" | curl -F "file=@-;filename=${base_name}" ${ROOTURL}upload/${SHARE}/${TOKEN}
|
||||
}
|
||||
send_folder() {
|
||||
which pv &> /dev/null && printf -v dusize -- "--size %%dk" $( du -s -B 1024 "$file_name" | cut -f1 )
|
||||
tar cz "$file_name" | $CAT $dusize - | curl -F "file=@-;filename=${base_name}.tgz" ${ROOTURL}upload/${SHARE}/${TOKEN}
|
||||
}
|
||||
|
||||
for file_name in "$@"; do
|
||||
base_name=$( basename "$file_name" )
|
||||
test -f "$file_name" || {
|
||||
echo "'$file_name' not a file"
|
||||
continue
|
||||
test -f "$file_name" && {
|
||||
printf "Sending file: %%s\n" "$file_name"
|
||||
send_file
|
||||
continue
|
||||
}
|
||||
test -d "$file_name" && {
|
||||
printf "Sending folder: %%s\n" "$file_name"
|
||||
send_folder
|
||||
continue
|
||||
}
|
||||
|
||||
$CAT "$file_name" | curl -F "file=@-;filename=${base_name}" %supload/%s/%s
|
||||
done
|
||||
"""%(
|
||||
request.url_root,
|
||||
|
||||
Reference in New Issue
Block a user