added text paste area
This commit is contained in:
parent
8d01dfbd33
commit
47d3dc5b0b
22
fileHost.py
22
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__":
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue
Block a user