diff --git a/t0txt.py b/t0txt.py index 023259f..0713790 100644 --- a/t0txt.py +++ b/t0txt.py @@ -16,10 +16,13 @@ def help(): form = ( '
'.format(URL, POST) ) return """ +
txt.t0.vc
NAME
@@ -28,7 +31,6 @@ NAME
USAGE
<command> | curl -F '{0}=<-' {1}
or upload from the web:
-
{2}
DESCRIPTION
@@ -68,21 +70,42 @@ def index():
@flask_app.route('/', methods=['POST'])
def new():
+ print()
try:
+ is_web = 'web' in request.form
+
+ name = request.form.get('name', None)
+ if name:
+ print('Name filled out:', name)
+
+ captcha = request.form.get('captcha', None)
+ if is_web and captcha.lower() not in ['tanner', 'tanner collin', 'tannercollin', 'collin']:
+ print('Captcha failed:', captcha)
+ return redirect('https://txt.t0.vc/LPPZ')
+ else:
+ print('Captcha passed:', captcha)
+
with shelve.open(DB) as db:
nid = new_id()
while nid in db:
nid = new_id()
txt = request.form['txt']
- if not txt: raise
- if len(txt) > 250000: raise
+
+ if not txt:
+ print('Note is empty.')
+ raise
+ if len(txt) > 250000:
+ print('Note too large.')
+ raise
+
db[nid] = txt
- print('Adding note {}:\n{}'.format(nid, txt))
+ print('Adding note {} via {}:\n{}'.format(nid, 'web' if is_web else 'api', txt))
url = '{}/{}'.format(URL, nid)
- if 'web' in request.form:
+
+ if is_web:
return redirect(url)
else:
return url + '\n'