From 73e48d2209f5c0ce99b60ef2ae15807c20ae1507 Mon Sep 17 00:00:00 2001 From: iou1name Date: Tue, 12 Jun 2018 12:12:42 -0400 Subject: [PATCH] split upload function from the index, made uploading from index return a proper html page, added /upload api endpoint --- fileHost.py | 25 +++++++++++++++++-------- templates/index.html | 2 +- templates/result.html | 11 +++++++++++ 3 files changed, 29 insertions(+), 9 deletions(-) create mode 100644 templates/result.html diff --git a/fileHost.py b/fileHost.py index 2d3b3d6..e945b43 100755 --- a/fileHost.py +++ b/fileHost.py @@ -363,20 +363,17 @@ def gallery(username): upload_url=app.config.get("UPLOAD_URL")) -@app.route("/", methods=["POST", "GET"]) +@app.route("/upload", methods=["POST"]) @login_required("login") -def index(): +def upload(): """ - Saves the uploaded file and returns a URL pointing to it. + Saves the uploaded files and returns URLs pointing to them. """ - if request.method == "GET": - return render_template("index.html") - username = session.get("username") if not username: username = request.form.get("user") urls = [] - for file in request.files.getlist("file"): + for file in request.files.getlist("files"): fname = secure_filename(file.filename) pre = get_rand_chars(8) fdir = app.config.get("UPLOAD_DIR") @@ -409,7 +406,19 @@ def index(): file.save(os.path.join(fdir, fname)) url = app.config.get("UPLOAD_URL") + fname urls.append(url) - return "
".join(urls) + return "\n".join(urls) + + +@app.route("/", methods=["POST", "GET"]) +@login_required("login") +def index(): + """ + Saves the uploaded file and returns a URL pointing to it. + """ + if request.method == "GET": + return render_template("index.html") + urls = upload().split("\n") + return render_template("result.html", urls=urls) def get_rand_chars(n): diff --git a/templates/index.html b/templates/index.html index 1d648c3..a4f2cc2 100644 --- a/templates/index.html +++ b/templates/index.html @@ -11,7 +11,7 @@ Manage Uploads
Public Gallery

Select file to upload: -


+


Generate random filename.
Delete this file in