|
|
@ -3174,128 +3174,127 @@ def upload():
|
|
|
|
if not config.config_uploading:
|
|
|
|
if not config.config_uploading:
|
|
|
|
abort(404)
|
|
|
|
abort(404)
|
|
|
|
# create the function for sorting...
|
|
|
|
# create the function for sorting...
|
|
|
|
db.session.connection().connection.connection.create_function("title_sort", 1, db.title_sort)
|
|
|
|
|
|
|
|
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:
|
|
|
|
requested_file = request.files['btn-upload']
|
|
|
|
for requested_file in request.files.getlist("btn-upload"):
|
|
|
|
if '.' in requested_file.filename:
|
|
|
|
db.session.connection().connection.connection.create_function("title_sort", 1, db.title_sort)
|
|
|
|
file_ext = requested_file.filename.rsplit('.', 1)[-1].lower()
|
|
|
|
db.session.connection().connection.connection.create_function('uuid4', 0, lambda: str(uuid4()))
|
|
|
|
if file_ext not in ALLOWED_EXTENSIONS:
|
|
|
|
if '.' in requested_file.filename:
|
|
|
|
flash(
|
|
|
|
file_ext = requested_file.filename.rsplit('.', 1)[-1].lower()
|
|
|
|
_('File extension "%s" is not allowed to be uploaded to this server' %
|
|
|
|
if file_ext not in ALLOWED_EXTENSIONS:
|
|
|
|
file_ext),
|
|
|
|
flash(
|
|
|
|
category="error"
|
|
|
|
_('File extension "%s" is not allowed to be uploaded to this server' %
|
|
|
|
)
|
|
|
|
file_ext),
|
|
|
|
|
|
|
|
category="error"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
return redirect(url_for('index'))
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
flash(_('File to be uploaded must have an extension'), category="error")
|
|
|
|
return redirect(url_for('index'))
|
|
|
|
return redirect(url_for('index'))
|
|
|
|
else:
|
|
|
|
meta = uploader.upload(requested_file)
|
|
|
|
flash(_('File to be uploaded must have an extension'), category="error")
|
|
|
|
|
|
|
|
return redirect(url_for('index'))
|
|
|
|
title = meta.title
|
|
|
|
meta = uploader.upload(requested_file)
|
|
|
|
author = meta.author
|
|
|
|
|
|
|
|
tags = meta.tags
|
|
|
|
title = meta.title
|
|
|
|
series = meta.series
|
|
|
|
author = meta.author
|
|
|
|
series_index = meta.series_id
|
|
|
|
tags = meta.tags
|
|
|
|
title_dir = helper.get_valid_filename(title)
|
|
|
|
series = meta.series
|
|
|
|
author_dir = helper.get_valid_filename(author)
|
|
|
|
series_index = meta.series_id
|
|
|
|
data_name = title_dir
|
|
|
|
title_dir = helper.get_valid_filename(title)
|
|
|
|
filepath = config.config_calibre_dir + os.sep + author_dir + os.sep + title_dir
|
|
|
|
author_dir = helper.get_valid_filename(author)
|
|
|
|
saved_filename = filepath + os.sep + data_name + meta.extension.lower()
|
|
|
|
data_name = title_dir
|
|
|
|
|
|
|
|
filepath = config.config_calibre_dir + os.sep + author_dir + os.sep + title_dir
|
|
|
|
if not os.path.exists(filepath):
|
|
|
|
saved_filename = filepath + os.sep + data_name + meta.extension.lower()
|
|
|
|
try:
|
|
|
|
|
|
|
|
os.makedirs(filepath)
|
|
|
|
if not os.path.exists(filepath):
|
|
|
|
except OSError:
|
|
|
|
|
|
|
|
flash(_(u"Failed to create path %s (Permission denied)." % filepath), category="error")
|
|
|
|
|
|
|
|
return redirect(url_for('index'))
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
os.makedirs(filepath)
|
|
|
|
copyfile(meta.file_path, 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 (Permission denied)." % saved_filename), category="error")
|
|
|
|
return redirect(url_for('index'))
|
|
|
|
return redirect(url_for('index'))
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
copyfile(meta.file_path, saved_filename)
|
|
|
|
os.unlink(meta.file_path)
|
|
|
|
except OSError:
|
|
|
|
except OSError:
|
|
|
|
flash(_(u"Failed to store file %s (Permission denied)." % saved_filename), category="error")
|
|
|
|
flash(_(u"Failed to delete file %s (Permission denied)." % meta.file_path), category="warning")
|
|
|
|
return redirect(url_for('index'))
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
os.unlink(meta.file_path)
|
|
|
|
|
|
|
|
except OSError:
|
|
|
|
|
|
|
|
flash(_(u"Failed to delete file %s (Permission denied)." % meta.file_path), category="warning")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
file_size = os.path.getsize(saved_filename)
|
|
|
|
file_size = os.path.getsize(saved_filename)
|
|
|
|
if meta.cover is None:
|
|
|
|
if meta.cover is None:
|
|
|
|
has_cover = 0
|
|
|
|
has_cover = 0
|
|
|
|
basedir = os.path.dirname(__file__)
|
|
|
|
basedir = os.path.dirname(__file__)
|
|
|
|
copyfile(os.path.join(basedir, "static/generic_cover.jpg"), os.path.join(filepath, "cover.jpg"))
|
|
|
|
copyfile(os.path.join(basedir, "static/generic_cover.jpg"), os.path.join(filepath, "cover.jpg"))
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
has_cover = 1
|
|
|
|
has_cover = 1
|
|
|
|
move(meta.cover, os.path.join(filepath, "cover.jpg"))
|
|
|
|
move(meta.cover, os.path.join(filepath, "cover.jpg"))
|
|
|
|
|
|
|
|
|
|
|
|
is_author = db.session.query(db.Authors).filter(db.Authors.name == author).first()
|
|
|
|
is_author = db.session.query(db.Authors).filter(db.Authors.name == author).first()
|
|
|
|
if is_author:
|
|
|
|
if is_author:
|
|
|
|
db_author = is_author
|
|
|
|
db_author = is_author
|
|
|
|
else:
|
|
|
|
|
|
|
|
db_author = db.Authors(author, helper.get_sorted_author(author), "")
|
|
|
|
|
|
|
|
db.session.add(db_author)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db_series = None
|
|
|
|
|
|
|
|
is_series = db.session.query(db.Series).filter(db.Series.name == series).first()
|
|
|
|
|
|
|
|
if is_series:
|
|
|
|
|
|
|
|
db_series = is_series
|
|
|
|
|
|
|
|
elif series != '':
|
|
|
|
|
|
|
|
db_series = db.Series(series, "")
|
|
|
|
|
|
|
|
db.session.add(db_series)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# add language actually one value in list
|
|
|
|
|
|
|
|
input_language = meta.languages
|
|
|
|
|
|
|
|
db_language = None
|
|
|
|
|
|
|
|
if input_language != "":
|
|
|
|
|
|
|
|
input_language = isoLanguages.get(name=input_language).part3
|
|
|
|
|
|
|
|
hasLanguage = db.session.query(db.Languages).filter(db.Languages.lang_code == input_language).first()
|
|
|
|
|
|
|
|
if hasLanguage:
|
|
|
|
|
|
|
|
db_language = hasLanguage
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
db_language = db.Languages(input_language)
|
|
|
|
db_author = db.Authors(author, helper.get_sorted_author(author), "")
|
|
|
|
db.session.add(db_language)
|
|
|
|
db.session.add(db_author)
|
|
|
|
# combine path and normalize path from windows systems
|
|
|
|
|
|
|
|
path = os.path.join(author_dir, title_dir).replace('\\', '/')
|
|
|
|
db_series = None
|
|
|
|
db_book = db.Books(title, "", db_author.sort, datetime.datetime.now(), datetime.datetime(101, 1, 1),
|
|
|
|
is_series = db.session.query(db.Series).filter(db.Series.name == series).first()
|
|
|
|
series_index, datetime.datetime.now(), path, has_cover, db_author, [], db_language)
|
|
|
|
if is_series:
|
|
|
|
db_book.authors.append(db_author)
|
|
|
|
db_series = is_series
|
|
|
|
if db_series:
|
|
|
|
elif series != '':
|
|
|
|
db_book.series.append(db_series)
|
|
|
|
db_series = db.Series(series, "")
|
|
|
|
if db_language is not None:
|
|
|
|
db.session.add(db_series)
|
|
|
|
db_book.languages.append(db_language)
|
|
|
|
|
|
|
|
db_data = db.Data(db_book, meta.extension.upper()[1:], file_size, data_name)
|
|
|
|
# add language actually one value in list
|
|
|
|
db_book.data.append(db_data)
|
|
|
|
input_language = meta.languages
|
|
|
|
|
|
|
|
db_language = None
|
|
|
|
db.session.add(db_book)
|
|
|
|
if input_language != "":
|
|
|
|
db.session.flush() # flush content get db_book.id avalible
|
|
|
|
input_language = isoLanguages.get(name=input_language).part3
|
|
|
|
# add comment
|
|
|
|
hasLanguage = db.session.query(db.Languages).filter(db.Languages.lang_code == input_language).first()
|
|
|
|
upload_comment = Markup(meta.description).unescape()
|
|
|
|
if hasLanguage:
|
|
|
|
if upload_comment != "":
|
|
|
|
db_language = hasLanguage
|
|
|
|
db.session.add(db.Comments(upload_comment, db_book.id))
|
|
|
|
else:
|
|
|
|
db.session.commit()
|
|
|
|
db_language = db.Languages(input_language)
|
|
|
|
|
|
|
|
db.session.add(db_language)
|
|
|
|
|
|
|
|
# combine path and normalize path from windows systems
|
|
|
|
|
|
|
|
path = os.path.join(author_dir, title_dir).replace('\\', '/')
|
|
|
|
|
|
|
|
db_book = db.Books(title, "", db_author.sort, datetime.datetime.now(), datetime.datetime(101, 1, 1),
|
|
|
|
|
|
|
|
series_index, datetime.datetime.now(), path, has_cover, db_author, [], db_language)
|
|
|
|
|
|
|
|
db_book.authors.append(db_author)
|
|
|
|
|
|
|
|
if db_series:
|
|
|
|
|
|
|
|
db_book.series.append(db_series)
|
|
|
|
|
|
|
|
if db_language is not None:
|
|
|
|
|
|
|
|
db_book.languages.append(db_language)
|
|
|
|
|
|
|
|
db_data = db.Data(db_book, meta.extension.upper()[1:], file_size, data_name)
|
|
|
|
|
|
|
|
db_book.data.append(db_data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.session.add(db_book)
|
|
|
|
|
|
|
|
db.session.flush() # flush content get db_book.id avalible
|
|
|
|
|
|
|
|
# add comment
|
|
|
|
|
|
|
|
upload_comment = Markup(meta.description).unescape()
|
|
|
|
|
|
|
|
if upload_comment != "":
|
|
|
|
|
|
|
|
db.session.add(db.Comments(upload_comment, db_book.id))
|
|
|
|
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
|
|
|
input_tags = tags.split(',')
|
|
|
|
input_tags = tags.split(',')
|
|
|
|
input_tags = list(map(lambda it: it.strip(), input_tags))
|
|
|
|
input_tags = list(map(lambda it: it.strip(), input_tags))
|
|
|
|
modify_database_object(input_tags, db_book.tags, db.Tags, db.session, 'tags')
|
|
|
|
modify_database_object(input_tags, db_book.tags, db.Tags, db.session, 'tags')
|
|
|
|
|
|
|
|
|
|
|
|
if db_language is not None: # display Full name instead of iso639.part3
|
|
|
|
if db_language is not None: # display Full name instead of iso639.part3
|
|
|
|
db_book.languages[0].language_name = _(meta.languages)
|
|
|
|
db_book.languages[0].language_name = _(meta.languages)
|
|
|
|
author_names = []
|
|
|
|
author_names = []
|
|
|
|
for author in db_book.authors:
|
|
|
|
for author in db_book.authors:
|
|
|
|
author_names.append(author.name)
|
|
|
|
author_names.append(author.name)
|
|
|
|
if config.config_use_google_drive:
|
|
|
|
if config.config_use_google_drive:
|
|
|
|
updateGdriveCalibreFromLocal()
|
|
|
|
updateGdriveCalibreFromLocal()
|
|
|
|
cc = db.session.query(db.Custom_Columns).filter(db.Custom_Columns.datatype.notin_(db.cc_exceptions)).all()
|
|
|
|
if len(request.files.getlist("btn-upload")) < 2:
|
|
|
|
if current_user.role_edit() or current_user.role_admin():
|
|
|
|
cc = db.session.query(db.Custom_Columns).filter(db.Custom_Columns.datatype.notin_(db.cc_exceptions)).all()
|
|
|
|
return render_title_template('book_edit.html', book=db_book, authors=author_names, cc=cc,
|
|
|
|
if current_user.role_edit() or current_user.role_admin():
|
|
|
|
title=_(u"edit metadata"))
|
|
|
|
return render_title_template('book_edit.html', book=db_book, authors=author_names, cc=cc,title=_(u"edit metadata"))
|
|
|
|
book_in_shelfs = []
|
|
|
|
book_in_shelfs = []
|
|
|
|
return render_title_template('detail.html', entry=db_book, cc=cc, title=db_book.title,
|
|
|
|
return render_title_template('detail.html', entry=db_book, cc=cc, title=db_book.title, books_shelfs=book_in_shelfs, )
|
|
|
|
books_shelfs=book_in_shelfs, )
|
|
|
|
return redirect(url_for("index"))
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return redirect(url_for("index"))
|
|
|
|
return redirect(url_for("index"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def start_gevent():
|
|
|
|
def start_gevent():
|
|
|
|
from gevent.wsgi import WSGIServer
|
|
|
|
from gevent.wsgi import WSGIServer
|
|
|
|
global gevent_server
|
|
|
|
global gevent_server
|
|
|
|