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()
@@ -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