From 47d3dc5b0bc48c79821f5326054031e12e899eb4 Mon Sep 17 00:00:00 2001 From: iou1name Date: Fri, 12 Apr 2019 18:53:16 -0400 Subject: [PATCH] added text paste area --- fileHost.py | 22 ++++++++++++++++++++-- templates/index.html | 3 ++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/fileHost.py b/fileHost.py index 19a427c..7d4cf92 100755 --- a/fileHost.py +++ b/fileHost.py @@ -344,7 +344,12 @@ def upload(): try: f = [download_file(request.form.get("url"))] except ValueError as e: - return e + return str(e) + if request.form.get("text"): + try: + f = [text_paste(request.form.get("text"))] + except Exception as e: + return str(e) else: f = [] @@ -354,8 +359,10 @@ def upload(): pre = get_rand_chars(8) fdir = app.config.get("UPLOAD_DIR") - if request.form.get("randname") == "on": + if request.form.get("randname") == "on" or request.form.get("text"): fname = pre + os.path.splitext(fname)[1] + if request.form.get("text"): + fname += ".txt" else: fname = pre + "_" + fname @@ -448,6 +455,17 @@ def download_file(url): return f +def text_paste(text): + """ + Simple wrapper to handle a text paste upload. + """ + t = tempfile.TemporaryFile() + t.write(bytes(text, encoding='utf8')) + t.seek(0) + f = FileStorage(stream=t, filename="", name='text') + return f + + init() atexit.register(scheduler.shutdown) if __name__ == "__main__": diff --git a/templates/index.html b/templates/index.html index 377c592..fadb760 100644 --- a/templates/index.html +++ b/templates/index.html @@ -20,7 +20,8 @@ - +
+