diff --git a/saddle.py b/saddle.py
index 48460bd..640303c 100644
--- a/saddle.py
+++ b/saddle.py
@@ -41,6 +41,12 @@ async def index(request):
files.append(handle_filefield(filefield, rand_name=rand_name))
if data.get('url'):
files.append(handle_url(data.get('url'), rand_name=rand_name))
+ if data.get('text'):
+ files.append(handle_text(
+ data.get('text'),
+ data.get('text_filename', ''),
+ rand_name=rand_name)
+ )
if data.get('delete_this'):
delete_num = data.get('delete_num', '')
@@ -134,6 +140,25 @@ def handle_url(url, rand_name=True):
return tup
+def handle_text(text, filename, rand_name=True):
+ """Handles a posted text field."""
+ filename = safe_filename(filename)
+ if not filename:
+ rand_name = True
+ prefix = get_rand_chars()
+ if rand_name:
+ filename = prefix + os.path.splitext(filename)[1]
+ else:
+ filename = prefix + '_' + filename
+ filename = filename + '.txt'
+
+ with open(os.path.join(config.upload_dir, filename), 'w') as file:
+ file.write(text)
+
+ tup = (prefix, filename)
+ return tup
+
+
def safe_filename(filename=''):
"""Sanitizes the given filename."""
safe_char = string.ascii_letters + string.digits + '._ '
diff --git a/static/saddle.js b/static/saddle.js
index aa67383..473db1a 100644
--- a/static/saddle.js
+++ b/static/saddle.js
@@ -11,3 +11,12 @@ function switchFileTab(span, window_id) {
let tab_window = document.querySelector('#' + window_id);
tab_window.classList.add('tabWindowSelected');
}
+
+function disable_text_filename(checkbox) {
+ let input = document.querySelector('#text_filename');
+ if (checkbox.checked) {
+ input.disabled = true;
+ } else {
+ input.disabled = false;
+ }
+}
diff --git a/templates/index.html b/templates/index.html
index d5e025f..549495b 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -27,10 +27,12 @@