more helpers for uploading

This commit is contained in:
Ville Rantanen
2018-02-13 21:42:02 +02:00
parent 98035cea41
commit 5cec2f2a19
2 changed files with 27 additions and 2 deletions

View File

@@ -196,6 +196,31 @@ def download_zip(name,password = None):
attachment_filename = name + ".zip"
)
@app.route('/script/upload/<name>/<password>', methods=['GET'])
def script_upload(name = None, password = None):
session[name] = password
(ok,share) = get_share(name)
if not ok:
return share
if not get_or_none(share,'upload') == True:
return "Upload not allowed",400
return """#!/bin/bash
file_name="$1"
base_name=$( basename "$1" )
test -f "$file_name" || {
echo "Add file as argument"
exit 1
}
CAT=$( which cat )
which pv &> /dev/null && CAT=$( which pv )
$CAT "$file_name" | curl -F "file=@-;filename=${base_name}" %supload/%s/%s
"""%(
request.url_root,
name,
password
)
def file_stat(filename):
s = os.stat(filename)