1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-11-24 18:47:23 +00:00

bug fix with uploading limit

This commit is contained in:
idalin 2017-02-17 15:05:17 +08:00
parent fe2383516d
commit e02a91526e

View File

@ -52,7 +52,7 @@ from cgi import escape
# Global variables # Global variables
global_task = None global_task = None
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'epub', 'mobi', 'azw', 'azw3', 'cbr', 'cbz', 'cbt', 'djvu', 'prc', 'doc', 'docx']) ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'epub', 'mobi', 'azw', 'azw3', 'cbr', 'cbz', 'cbt', 'djvu', 'prc', 'doc', 'docx', 'fb2'])
# Proxy Helper class # Proxy Helper class
@ -2116,13 +2116,18 @@ def upload():
db.session.connection().connection.connection.create_function('uuid4', 0, lambda: str(uuid4())) db.session.connection().connection.connection.create_function('uuid4', 0, lambda: str(uuid4()))
if request.method == 'POST' and 'btn-upload' in request.files: if request.method == 'POST' and 'btn-upload' in request.files:
file = request.files['btn-upload'] file = request.files['btn-upload']
if not ('.' in file.filename and file.filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS): if '.' in file.filename:
file_ext = file.filename.rsplit('.', 1)[-1].lower()
if file_ext not in ALLOWED_EXTENSIONS:
flash( flash(
_('File extension "%s" is not allowed to be uploaded to this server' % _('File extension "%s" is not allowed to be uploaded to this server' %
file.filename.rsplit('.', 1)[1].lower()), file_ext),
category="error" category="error"
) )
return redirect(url_for('index')) return redirect(url_for('index'))
else:
flash(_('File to be uploaded must have an extension'), category="error")
return redirect(url_for('index'))
meta = uploader.upload(file) meta = uploader.upload(file)
title = meta.title title = meta.title