|
|
|
@ -883,20 +883,7 @@ def create_book_on_upload(modif_date, meta):
|
|
|
|
|
calibre_db.session.flush()
|
|
|
|
|
return db_book, input_authors, title_dir
|
|
|
|
|
|
|
|
|
|
@editbook.route("/upload", methods=["GET", "POST"])
|
|
|
|
|
@login_required_if_no_ano
|
|
|
|
|
@upload_required
|
|
|
|
|
def upload():
|
|
|
|
|
if not config.config_uploading:
|
|
|
|
|
abort(404)
|
|
|
|
|
if request.method == 'POST' and 'btn-upload' in request.files:
|
|
|
|
|
for requested_file in request.files.getlist("btn-upload"):
|
|
|
|
|
try:
|
|
|
|
|
modif_date = False
|
|
|
|
|
# create the function for sorting...
|
|
|
|
|
calibre_db.update_title_sort(config)
|
|
|
|
|
calibre_db.session.connection().connection.connection.create_function('uuid4', 0, lambda: str(uuid4()))
|
|
|
|
|
|
|
|
|
|
def file_handling_on_upload(requested_file):
|
|
|
|
|
# check if file extension is correct
|
|
|
|
|
if '.' in requested_file.filename:
|
|
|
|
|
file_ext = requested_file.filename.rsplit('.', 1)[-1].lower()
|
|
|
|
@ -904,10 +891,10 @@ def upload():
|
|
|
|
|
flash(
|
|
|
|
|
_("File extension '%(ext)s' is not allowed to be uploaded to this server",
|
|
|
|
|
ext=file_ext), category="error")
|
|
|
|
|
return Response(json.dumps({"location": url_for("web.index")}), mimetype='application/json')
|
|
|
|
|
return None, Response(json.dumps({"location": url_for("web.index")}), mimetype='application/json')
|
|
|
|
|
else:
|
|
|
|
|
flash(_('File to be uploaded must have an extension'), category="error")
|
|
|
|
|
return Response(json.dumps({"location": url_for("web.index")}), mimetype='application/json')
|
|
|
|
|
return None, Response(json.dumps({"location": url_for("web.index")}), mimetype='application/json')
|
|
|
|
|
|
|
|
|
|
# extract metadata from file
|
|
|
|
|
try:
|
|
|
|
@ -916,22 +903,11 @@ def upload():
|
|
|
|
|
log.error("File %s could not saved to temp dir", requested_file.filename)
|
|
|
|
|
flash(_(u"File %(filename)s could not saved to temp dir",
|
|
|
|
|
filename=requested_file.filename), category="error")
|
|
|
|
|
return Response(json.dumps({"location": url_for("web.index")}), mimetype='application/json')
|
|
|
|
|
|
|
|
|
|
db_book, input_authors, title_dir = create_book_on_upload(modif_date, meta)
|
|
|
|
|
|
|
|
|
|
# Comments needs book id therfore only possible after flush
|
|
|
|
|
modif_date |= edit_book_comments(Markup(meta.description).unescape(), db_book)
|
|
|
|
|
return None, Response(json.dumps({"location": url_for("web.index")}), mimetype='application/json')
|
|
|
|
|
return meta, None
|
|
|
|
|
|
|
|
|
|
book_id = db_book.id
|
|
|
|
|
title = db_book.title
|
|
|
|
|
|
|
|
|
|
error = helper.update_dir_structure_file(book_id,
|
|
|
|
|
config.config_calibre_dir,
|
|
|
|
|
input_authors[0],
|
|
|
|
|
meta.file_path,
|
|
|
|
|
title_dir + meta.extension)
|
|
|
|
|
|
|
|
|
|
def move_coverfile(meta, db_book):
|
|
|
|
|
# move cover to final directory, including book id
|
|
|
|
|
if meta.cover:
|
|
|
|
|
coverfile = meta.cover
|
|
|
|
@ -948,6 +924,43 @@ def upload():
|
|
|
|
|
error=e),
|
|
|
|
|
category="error")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@editbook.route("/upload", methods=["GET", "POST"])
|
|
|
|
|
@login_required_if_no_ano
|
|
|
|
|
@upload_required
|
|
|
|
|
def upload():
|
|
|
|
|
if not config.config_uploading:
|
|
|
|
|
abort(404)
|
|
|
|
|
if request.method == 'POST' and 'btn-upload' in request.files:
|
|
|
|
|
for requested_file in request.files.getlist("btn-upload"):
|
|
|
|
|
try:
|
|
|
|
|
modif_date = False
|
|
|
|
|
# create the function for sorting...
|
|
|
|
|
calibre_db.update_title_sort(config)
|
|
|
|
|
calibre_db.session.connection().connection.connection.create_function('uuid4', 0, lambda: str(uuid4()))
|
|
|
|
|
|
|
|
|
|
response, error = file_handling_on_upload(requested_file)
|
|
|
|
|
if error:
|
|
|
|
|
return response
|
|
|
|
|
else:
|
|
|
|
|
meta = response
|
|
|
|
|
|
|
|
|
|
db_book, input_authors, title_dir = create_book_on_upload(modif_date, meta)
|
|
|
|
|
|
|
|
|
|
# Comments needs book id therefore only possible after flush
|
|
|
|
|
modif_date |= edit_book_comments(Markup(meta.description).unescape(), db_book)
|
|
|
|
|
|
|
|
|
|
book_id = db_book.id
|
|
|
|
|
title = db_book.title
|
|
|
|
|
|
|
|
|
|
error = helper.update_dir_structure_file(book_id,
|
|
|
|
|
config.config_calibre_dir,
|
|
|
|
|
input_authors[0],
|
|
|
|
|
meta.file_path,
|
|
|
|
|
title_dir + meta.extension)
|
|
|
|
|
|
|
|
|
|
move_coverfile(meta, db_book)
|
|
|
|
|
|
|
|
|
|
# save data to database, reread data
|
|
|
|
|
calibre_db.session.commit()
|
|
|
|
|
|
|
|
|
|