dl route shorted

This commit is contained in:
2023-08-20 11:05:18 +03:00
parent 654891a61e
commit 8377ed7508
3 changed files with 12 additions and 13 deletions

View File

@@ -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()
@@ -106,7 +104,7 @@ def upload():
if request.method == "PUT":
chunk_size = 1024 * 1024 * 64 # 64Mb
with open(filename, 'wb') as f:
with open(filename, "wb") as f:
while True:
chunk = request.stream.read(chunk_size)
if not chunk:
@@ -117,6 +115,7 @@ def upload():
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

View 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():

View File

@@ -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"