dl route shorted
This commit is contained in:
15
code/app.py
15
code/app.py
@@ -42,7 +42,7 @@ def index():
|
||||
return "", 200
|
||||
|
||||
|
||||
@app.route("/upload", methods=["PUT","POST"])
|
||||
@app.route("/upload", methods=["PUT", "POST"])
|
||||
def upload():
|
||||
"""
|
||||
Upload a file, example CURL:
|
||||
@@ -85,9 +85,7 @@ def upload():
|
||||
request.headers.get("Expires-days")
|
||||
)
|
||||
if "Expires-hours" in request.headers:
|
||||
expires = int(time.time()) + 3600 * int(
|
||||
request.headers.get("Expires-hours")
|
||||
)
|
||||
expires = int(time.time()) + 3600 * int(request.headers.get("Expires-hours"))
|
||||
|
||||
while True:
|
||||
token = random_token()
|
||||
@@ -105,18 +103,19 @@ def upload():
|
||||
return "Use the 'file' variable to upload\n", 400
|
||||
|
||||
if request.method == "PUT":
|
||||
chunk_size = 1024 * 1024 * 64 # 64Mb
|
||||
with open(filename, 'wb') as f:
|
||||
chunk_size = 1024 * 1024 * 64 # 64Mb
|
||||
with open(filename, "wb") as f:
|
||||
while True:
|
||||
chunk = request.stream.read(chunk_size)
|
||||
if not chunk:
|
||||
break
|
||||
break
|
||||
f.write(chunk)
|
||||
|
||||
db_store_file(token, safe_filename, expires, max_dl)
|
||||
download_url = file_full_url(token, safe_filename)
|
||||
return "File uploaded\n%s\n" % (download_url,), 200
|
||||
|
||||
|
||||
@app.route("/details/<token>/<name>", methods=["GET"])
|
||||
def details(token, name):
|
||||
"""
|
||||
@@ -174,7 +173,7 @@ def maintenance():
|
||||
return db_maintenance(), 200
|
||||
|
||||
|
||||
@app.route("/dl/<token>/<name>", methods=["GET"])
|
||||
@app.route("/d/<token>/<name>", methods=["GET"])
|
||||
def download(name, token):
|
||||
"""
|
||||
Download a file
|
||||
|
||||
@@ -179,7 +179,7 @@ def file_full_path(token, name):
|
||||
|
||||
|
||||
def file_full_url(token, name):
|
||||
return f"{app.config['PUBLIC_URL']}/dl/{token}/{name}"
|
||||
return f"{app.config['PUBLIC_URL']}/d/{token}/{name}"
|
||||
|
||||
|
||||
def file_list():
|
||||
|
||||
@@ -177,7 +177,7 @@ function t08-file-details() {
|
||||
download_url=$( curl -fL -w "\n" \
|
||||
-H "Secret: $FLASK_ACCESS_TOKEN" \
|
||||
"$FLASK_PUBLIC_URL"/ls | grep "$BIGS" | tail -n 1 | sed s,.*http,http, )
|
||||
token_name=$( echo $download_url | sed s,.*/dl/,, )
|
||||
token_name=$( echo $download_url | sed s,.*/d/,, )
|
||||
curl -fL -w "\n" \
|
||||
-H "Secret: $FLASK_ACCESS_TOKEN" \
|
||||
"$FLASK_PUBLIC_URL"/details/"$token_name"
|
||||
@@ -188,7 +188,7 @@ function t09-file-delete() {
|
||||
download_url=$( curl -fL -w "\n" \
|
||||
-H "Secret: $FLASK_ACCESS_TOKEN" \
|
||||
"$FLASK_PUBLIC_URL"/ls | grep "$BIGS" | tail -n 1 | sed s,.*http,http, )
|
||||
token_name=$( echo $download_url | sed s,.*/dl/,, )
|
||||
token_name=$( echo $download_url | sed s,.*/d/,, )
|
||||
curl -fL -w "\n" \
|
||||
-H "Secret: $FLASK_ACCESS_TOKEN" \
|
||||
"$FLASK_PUBLIC_URL"/delete/"$token_name"
|
||||
@@ -205,11 +205,11 @@ function t09-unlimited-downloads() {
|
||||
download_url=$( curl -fL -w "\n" \
|
||||
-H "Secret: $FLASK_ACCESS_TOKEN" \
|
||||
"$FLASK_PUBLIC_URL"/ls | grep "$SMALLS" | tail -n 1 | sed s,.*http,http, )
|
||||
token_name=$( echo $download_url | sed s,.*/dl/,, )
|
||||
token_name=$( echo $download_url | sed s,.*/d/,, )
|
||||
for ((i=0;i<10;i++)); do
|
||||
curl -fL -w "\n" \
|
||||
-H "Secret: $FLASK_ACCESS_TOKEN" \
|
||||
"$FLASK_PUBLIC_URL"/dl/"$token_name" > /dev/null
|
||||
"$FLASK_PUBLIC_URL"/d/"$token_name" > /dev/null
|
||||
curl -fL -w "\n" \
|
||||
-H "Secret: $FLASK_ACCESS_TOKEN" \
|
||||
"$FLASK_PUBLIC_URL"/details/"$token_name"
|
||||
|
||||
Reference in New Issue
Block a user