|
|
@ -550,13 +550,19 @@ def upload():
|
|
|
|
flash(
|
|
|
|
flash(
|
|
|
|
_("File extension '%(ext)s' is not allowed to be uploaded to this server",
|
|
|
|
_("File extension '%(ext)s' is not allowed to be uploaded to this server",
|
|
|
|
ext=file_ext), category="error")
|
|
|
|
ext=file_ext), category="error")
|
|
|
|
return redirect(url_for('web.index'))
|
|
|
|
return Response(json.dumps({"location": url_for("web.index")}), mimetype='application/json')
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
flash(_('File to be uploaded must have an extension'), category="error")
|
|
|
|
flash(_('File to be uploaded must have an extension'), category="error")
|
|
|
|
return redirect(url_for('web.index'))
|
|
|
|
return Response(json.dumps({"location": url_for("web.index")}), mimetype='application/json')
|
|
|
|
|
|
|
|
|
|
|
|
# extract metadata from file
|
|
|
|
# extract metadata from file
|
|
|
|
|
|
|
|
try:
|
|
|
|
meta = uploader.upload(requested_file)
|
|
|
|
meta = uploader.upload(requested_file)
|
|
|
|
|
|
|
|
except (IOError, OSError):
|
|
|
|
|
|
|
|
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')
|
|
|
|
title = meta.title
|
|
|
|
title = meta.title
|
|
|
|
authr = meta.author
|
|
|
|
authr = meta.author
|
|
|
|
tags = meta.tags
|
|
|
|
tags = meta.tags
|
|
|
@ -570,7 +576,8 @@ def upload():
|
|
|
|
if title != u'Unknown' and authr != u'Unknown':
|
|
|
|
if title != u'Unknown' and authr != u'Unknown':
|
|
|
|
entry = helper.check_exists_book(authr, title)
|
|
|
|
entry = helper.check_exists_book(authr, title)
|
|
|
|
if entry:
|
|
|
|
if entry:
|
|
|
|
book_html = flash(_(u"Uploaded book probably exists in the library, consider to change before upload new: ")
|
|
|
|
log.info("Uploaded book probably exists in library")
|
|
|
|
|
|
|
|
flash(_(u"Uploaded book probably exists in the library, consider to change before upload new: ")
|
|
|
|
+ Markup(render_title_template('book_exists_flash.html', entry=entry)), category="warning")
|
|
|
|
+ Markup(render_title_template('book_exists_flash.html', entry=entry)), category="warning")
|
|
|
|
|
|
|
|
|
|
|
|
# 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
|
|
|
@ -578,16 +585,19 @@ def upload():
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
os.makedirs(filepath)
|
|
|
|
os.makedirs(filepath)
|
|
|
|
except OSError:
|
|
|
|
except OSError:
|
|
|
|
|
|
|
|
log.error("Failed to create path %s (Permission denied)", filepath)
|
|
|
|
flash(_(u"Failed to create path %(path)s (Permission denied).", path=filepath), category="error")
|
|
|
|
flash(_(u"Failed to create path %(path)s (Permission denied).", path=filepath), category="error")
|
|
|
|
return redirect(url_for('web.index'))
|
|
|
|
return Response(json.dumps({"location": url_for("web.index")}), mimetype='application/json')
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
copyfile(meta.file_path, saved_filename)
|
|
|
|
copyfile(meta.file_path, saved_filename)
|
|
|
|
except OSError:
|
|
|
|
except OSError:
|
|
|
|
|
|
|
|
log.error("Failed to store file %s (Permission denied)", saved_filename)
|
|
|
|
flash(_(u"Failed to store file %(file)s (Permission denied).", file=saved_filename), category="error")
|
|
|
|
flash(_(u"Failed to store file %(file)s (Permission denied).", file=saved_filename), category="error")
|
|
|
|
return redirect(url_for('web.index'))
|
|
|
|
return Response(json.dumps({"location": url_for("web.index")}), mimetype='application/json')
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
os.unlink(meta.file_path)
|
|
|
|
os.unlink(meta.file_path)
|
|
|
|
except OSError:
|
|
|
|
except OSError:
|
|
|
|
|
|
|
|
log.error("Failed to delete file %(file)s (Permission denied)", meta.file_path)
|
|
|
|
flash(_(u"Failed to delete file %(file)s (Permission denied).", file= meta.file_path),
|
|
|
|
flash(_(u"Failed to delete file %(file)s (Permission denied).", file= meta.file_path),
|
|
|
|
category="warning")
|
|
|
|
category="warning")
|
|
|
|
|
|
|
|
|
|
|
|