Fix for empty filename during edit
This commit is contained in:
parent
7dac87fa5d
commit
34abf95fb2
68
cps/web.py
Executable file → Normal file
68
cps/web.py
Executable file → Normal file
|
@ -3055,48 +3055,50 @@ def edit_book(book_id):
|
||||||
# Check and handle Uploaded file
|
# Check and handle Uploaded file
|
||||||
if 'btn-upload-format' in request.files:
|
if 'btn-upload-format' in request.files:
|
||||||
requested_file = request.files['btn-upload-format']
|
requested_file = request.files['btn-upload-format']
|
||||||
if '.' in requested_file.filename:
|
# check for empty request
|
||||||
file_ext = requested_file.filename.rsplit('.', 1)[-1].lower()
|
if requested_file.filename != '':
|
||||||
if file_ext not in ALLOWED_EXTENSIONS:
|
if '.' in requested_file.filename:
|
||||||
flash(_('File extension "%s" is not allowed to be uploaded to this server' % file_ext), category="error")
|
file_ext = requested_file.filename.rsplit('.', 1)[-1].lower()
|
||||||
|
if file_ext not in ALLOWED_EXTENSIONS:
|
||||||
|
flash(_('File extension "%s" is not allowed to be uploaded to this server' % file_ext), category="error")
|
||||||
|
return redirect(url_for('show_book', book_id=book.id))
|
||||||
|
else:
|
||||||
|
flash(_('File to be uploaded must have an extension'), category="error")
|
||||||
return redirect(url_for('show_book', book_id=book.id))
|
return redirect(url_for('show_book', book_id=book.id))
|
||||||
else:
|
|
||||||
flash(_('File to be uploaded must have an extension'), category="error")
|
|
||||||
return redirect(url_for('show_book', book_id=book.id))
|
|
||||||
|
|
||||||
file_name = book.path.rsplit('/', 1)[-1]
|
file_name = book.path.rsplit('/', 1)[-1]
|
||||||
filepath = os.path.normpath(os.path.join(config.config_calibre_dir, book.path))
|
filepath = os.path.normpath(os.path.join(config.config_calibre_dir, book.path))
|
||||||
saved_filename = os.path.join(filepath, file_name + '.' + file_ext)
|
saved_filename = os.path.join(filepath, file_name + '.' + file_ext)
|
||||||
|
|
||||||
# check if file path exists, otherwise create it, copy file to calibre path and delete temp file
|
# check if file path exists, otherwise create it, copy file to calibre path and delete temp file
|
||||||
if not os.path.exists(filepath):
|
if not os.path.exists(filepath):
|
||||||
|
try:
|
||||||
|
os.makedirs(filepath)
|
||||||
|
except OSError:
|
||||||
|
flash(_(u"Failed to create path %s (Permission denied)." % filepath), category="error")
|
||||||
|
return redirect(url_for('show_book', book_id=book.id))
|
||||||
try:
|
try:
|
||||||
os.makedirs(filepath)
|
requested_file.save(saved_filename)
|
||||||
except OSError:
|
except OSError:
|
||||||
flash(_(u"Failed to create path %s (Permission denied)." % filepath), category="error")
|
flash(_(u"Failed to store file %s." % saved_filename), category="error")
|
||||||
return redirect(url_for('show_book', book_id=book.id))
|
return redirect(url_for('show_book', book_id=book.id))
|
||||||
try:
|
|
||||||
requested_file.save(saved_filename)
|
|
||||||
except OSError:
|
|
||||||
flash(_(u"Failed to store file %s." % saved_filename), category="error")
|
|
||||||
return redirect(url_for('show_book', book_id=book.id))
|
|
||||||
|
|
||||||
file_size = os.path.getsize(saved_filename)
|
file_size = os.path.getsize(saved_filename)
|
||||||
is_format = db.session.query(db.Data).filter(db.Data.book == book_id).filter(db.Data.format == file_ext.upper()).first()
|
is_format = db.session.query(db.Data).filter(db.Data.book == book_id).filter(db.Data.format == file_ext.upper()).first()
|
||||||
|
|
||||||
# Format entry already exists, no need to update the database
|
# Format entry already exists, no need to update the database
|
||||||
if is_format:
|
if is_format:
|
||||||
app.logger.info('Book format already existing')
|
app.logger.info('Book format already existing')
|
||||||
else:
|
else:
|
||||||
db_format = db.Data(book_id, file_ext.upper(), file_size, file_name)
|
db_format = db.Data(book_id, file_ext.upper(), file_size, file_name)
|
||||||
db.session.add(db_format)
|
db.session.add(db_format)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
db.session.connection().connection.connection.create_function("title_sort", 1, db.title_sort)
|
db.session.connection().connection.connection.create_function("title_sort", 1, db.title_sort)
|
||||||
|
|
||||||
# Queue uploader info
|
# Queue uploader info
|
||||||
uploadText=_(u"File format %s added to %s" % (file_ext.upper(),book.title))
|
uploadText=_(u"File format %s added to %s" % (file_ext.upper(),book.title))
|
||||||
helper.global_WorkerThread.add_upload(current_user.nickname,
|
helper.global_WorkerThread.add_upload(current_user.nickname,
|
||||||
"<a href=\""+ url_for('show_book', book_id=book.id) +"\">"+ uploadText + "</a>")
|
"<a href=\""+ url_for('show_book', book_id=book.id) +"\">"+ uploadText + "</a>")
|
||||||
|
|
||||||
|
|
||||||
to_save = request.form.to_dict()
|
to_save = request.form.to_dict()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user