fix html vs. plaintext (for cli purposes) return result

This commit is contained in:
iou1name 2019-04-02 10:37:15 -04:00
parent 0fa57ac7a3
commit c7f90fb933
2 changed files with 10 additions and 7 deletions

View File

@ -170,6 +170,7 @@ def login_required(url=None):
username = request.form.get("user") username = request.form.get("user")
password = request.form.get("pass") password = request.form.get("pass")
if verify_password(username, password): if verify_password(username, password):
session["username"] = username
return func(*args, **kwargs) return func(*args, **kwargs)
if url: if url:
@ -381,19 +382,20 @@ def upload():
file.save(os.path.join(fdir, fname)) file.save(os.path.join(fdir, fname))
url = app.config.get("UPLOAD_URL") + fname url = app.config.get("UPLOAD_URL") + fname
urls.append(url) urls.append(url)
return "\n".join(urls)
if request.form.get("html"):
return render_template("result.html", urls=urls)
else:
return "\n".join(urls)
@app.route("/", methods=["POST", "GET"]) @app.route("/", methods=["GET"])
@login_required("login") @login_required("login")
def index(): def index():
""" """
Saves the uploaded file and returns a URL pointing to it. Saves the uploaded file and returns a URL pointing to it.
""" """
if request.method == "GET": return render_template("index.html")
return render_template("index.html")
urls = upload().split("\n")
return render_template("result.html", urls=urls)
def get_rand_chars(n): def get_rand_chars(n):

View File

@ -9,7 +9,7 @@
<a href="{{ url_for('logout') }}">Logout</a><br> <a href="{{ url_for('logout') }}">Logout</a><br>
<a href="{{ url_for('manage_uploads') }}">Manage Uploads</a><br> <a href="{{ url_for('manage_uploads') }}">Manage Uploads</a><br>
<a href="{{ url_for('gallery', username=session.username) }}">Public Gallery</a><br> <a href="{{ url_for('gallery', username=session.username) }}">Public Gallery</a><br>
<form method="post" enctype="multipart/form-data" action="{{ url_for('index') }}"> <form method="post" enctype="multipart/form-data" action="{{ url_for('upload') }}">
<p>Select file to upload: <p>Select file to upload:
<p><input type="file" name="files" multiple><br> <p><input type="file" name="files" multiple><br>
<input type="url" name="url" placeholder="URL" size="30"><br> <input type="url" name="url" placeholder="URL" size="30"><br>
@ -21,6 +21,7 @@
<option value="day" selected="selected">Day</option> <option value="day" selected="selected">Day</option>
<option value="week">Week</option> <option value="week">Week</option>
</select> </select>
<input type="hidden" name="html" value="on">
<p><input type="submit" value="Upload File" name="submit"> <p><input type="submit" value="Upload File" name="submit">
</form> </form>
</body> </body>