commit 430635cec5facbe40db9d6b69774c3165d68af76
parent b3476a0a1b7343d98ad082e24ee19e3b47cba313
Author: parazyd <parazyd@dyne.org>
Date: Tue, 9 Feb 2021 11:09:29 +0100
Code cleanup.
Diffstat:
M | blck.py | | | 25 | +++++++++++-------------- |
1 file changed, 11 insertions(+), 14 deletions(-)
diff --git a/blck.py b/blck.py
@@ -4,7 +4,7 @@
from io import BytesIO
from os import remove, rename
-from os.path import join, isfile
+from os.path import isfile
from random import choice
from string import ascii_uppercase, ascii_lowercase
@@ -15,7 +15,7 @@ import magic
bp = Blueprint('blck', __name__, template_folder='templates')
@bp.route("/", methods=['GET', 'POST'])
-def main():
+def index():
if request.method == 'GET':
return render_template('index.html', root=args.r)
return short(request.files)
@@ -41,23 +41,20 @@ def short(c):
s = genid()
f = c['c']
- f.save(join('files', s))
+ f.save(safe_join('files', s))
- mimetype = None
- if f.mimetype:
- mimetype = f.mimetype
- else:
- mimetype = magic.from_file(join('files', s), mime=True)
+ mimetype = f.mimetype
+ if not mimetype:
+ mimetype = magic.from_file(safe_join('files', s), mime=True)
if mimetype:
- t = s
- s = s + '.' + mimetype.split('/')[1]
- rename(join('files', t), join('files', s))
+ t, s = s, '.'.join([s, mimetype.split('/')[1]])
+ rename(safe_join('files', t), safe_join('files', s))
if request.headers.get('X-Forwarded-Proto') == 'https':
- return request.url_root.replace('http://', 'https://') + \
- args.r.lstrip('/') + s +'\n'
- return request.url_root + args.r.lstrip('/') + s + '\n'
+ return ''.join([request.url_root.replace('http://', 'https://'),
+ args.r.lstrip('/'), s, '\n'])
+ return ''.join([request.url_root + args.r.lstrip('/'), s, '\n'])
def genid(size=4, chars=ascii_uppercase + ascii_lowercase):