From 8377ed75081e0df7a4e73d8093b948533c76d02b Mon Sep 17 00:00:00 2001 From: Ville Rantanen Date: Sun, 20 Aug 2023 11:05:18 +0300 Subject: [PATCH] dl route shorted --- code/app.py | 15 +++++++-------- code/utils/files.py | 2 +- test/run-tests.sh | 8 ++++---- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/code/app.py b/code/app.py index 1cf7b7d..3a0158a 100644 --- a/code/app.py +++ b/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//", methods=["GET"]) def details(token, name): """ @@ -174,7 +173,7 @@ def maintenance(): return db_maintenance(), 200 -@app.route("/dl//", methods=["GET"]) +@app.route("/d//", methods=["GET"]) def download(name, token): """ Download a file diff --git a/code/utils/files.py b/code/utils/files.py index 9ae2332..9992839 100644 --- a/code/utils/files.py +++ b/code/utils/files.py @@ -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(): diff --git a/test/run-tests.sh b/test/run-tests.sh index 00d9c44..5647547 100755 --- a/test/run-tests.sh +++ b/test/run-tests.sh @@ -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"