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
|
import zipfile
|
||||||
from revprox import ReverseProxied
|
from revprox import ReverseProxied
|
||||||
|
|
||||||
__FLEES_VERSION__ = "20180219.0"
|
__FLEES_VERSION__ = "20180220.0"
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config.from_object(__name__)
|
app.config.from_object(__name__)
|
||||||
# Read config from json !
|
# Read config from json !
|
||||||
@@ -248,21 +248,36 @@ def script_upload(name = None, password = None):
|
|||||||
if not get_or_none(share,'upload') == True:
|
if not get_or_none(share,'upload') == True:
|
||||||
return "Upload not allowed",400
|
return "Upload not allowed",400
|
||||||
return """#!/bin/bash
|
return """#!/bin/bash
|
||||||
test -f "$1" || {
|
test -n "$1" || {
|
||||||
echo "Add files to upload as argument"
|
echo "Add files to upload as argument"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
CAT=$( which cat )
|
CAT=$( which cat )
|
||||||
which pv &> /dev/null && CAT=$( which pv )
|
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
|
for file_name in "$@"; do
|
||||||
base_name=$( basename "$file_name" )
|
base_name=$( basename "$file_name" )
|
||||||
test -f "$file_name" || {
|
test -f "$file_name" && {
|
||||||
echo "'$file_name' not a file"
|
printf "Sending file: %%s\n" "$file_name"
|
||||||
continue
|
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
|
done
|
||||||
"""%(
|
"""%(
|
||||||
request.url_root,
|
request.url_root,
|
||||||
|
|||||||
Reference in New Issue
Block a user