Compare commits

..

2 Commits

Author SHA1 Message Date
0da549d20d update readme 2019-09-13 18:37:28 -04:00
47d3dc5b0b added text paste area 2019-04-12 18:53:16 -04:00
3 changed files with 23 additions and 4 deletions

View File

@ -6,6 +6,6 @@ Note: I switched to Gunicorn at some point because Bjoern was somehow annoying.
Dependencies:
```passlib argon2_cffi flask gunicorn flask-paranoid apscheduler```
```passlib argon2_cffi flask gunicorn flask-paranoid apscheduler requests```
This application makes use of the `secrets` module (a cryptographically strong version of `random`) from the standard library, which is only available in Python 3.6+. If you really can't be bothered use the latest version of python3, or just don't want cryptographically strong random character filenames/prefixes for some reason, you can directly replace all instances of `secrets` with `random`.

View File

@ -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__":

View File

@ -20,7 +20,8 @@
<option value="hour">Hour</option>
<option value="day" selected="selected">Day</option>
<option value="week">Week</option>
</select>
</select><br>
<textarea name="text"></textarea><br>
<input type="hidden" name="html" value="on">
<p><input type="submit" value="Upload File" name="submit">
</form>