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