added text paste area

This commit is contained in:
iou1name 2019-04-12 18:53:16 -04:00
parent 8d01dfbd33
commit 47d3dc5b0b
2 changed files with 22 additions and 3 deletions

View File

@ -344,7 +344,12 @@ def upload():
try: try:
f = [download_file(request.form.get("url"))] f = [download_file(request.form.get("url"))]
except ValueError as e: 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: else:
f = [] f = []
@ -354,8 +359,10 @@ def upload():
pre = get_rand_chars(8) pre = get_rand_chars(8)
fdir = app.config.get("UPLOAD_DIR") 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] fname = pre + os.path.splitext(fname)[1]
if request.form.get("text"):
fname += ".txt"
else: else:
fname = pre + "_" + fname fname = pre + "_" + fname
@ -448,6 +455,17 @@ def download_file(url):
return f 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() init()
atexit.register(scheduler.shutdown) atexit.register(scheduler.shutdown)
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -20,7 +20,8 @@
<option value="hour">Hour</option> <option value="hour">Hour</option>
<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><br>
<textarea name="text"></textarea><br>
<input type="hidden" name="html" value="on"> <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>