1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-10-31 23:26:20 +00:00

Fix response opds with read/unread

changed db_reconnect
Changed output for error 500 (now including error message)
Fix in task queue after 20 messages
This commit is contained in:
Ozzieisaacs 2019-12-24 13:02:53 +01:00
parent b586a32843
commit 62e8bee2a8
5 changed files with 3012 additions and 1483 deletions

View File

@ -33,7 +33,7 @@ from sqlalchemy.ext.declarative import declarative_base
session = None session = None
cc_exceptions = ['datetime', 'comments', 'float', 'composite', 'series'] cc_exceptions = ['datetime', 'comments', 'float', 'composite', 'series']
cc_classes = {} cc_classes = {}
engine = None
Base = declarative_base() Base = declarative_base()
@ -288,7 +288,7 @@ class Books(Base):
@property @property
def atom_timestamp(self): def atom_timestamp(self):
return (self.timestamp or '').replace(' ', 'T') return (self.timestamp.strftime('%Y-%m-%dT%H:%M:%S+00:00') or '')
class Custom_Columns(Base): class Custom_Columns(Base):
__tablename__ = 'custom_columns' __tablename__ = 'custom_columns'
@ -327,6 +327,7 @@ def update_title_sort(config, conn=None):
def setup_db(config): def setup_db(config):
dispose() dispose()
global engine
if not config.config_calibre_dir: if not config.config_calibre_dir:
config.invalidate() config.invalidate()
@ -428,3 +429,8 @@ def dispose():
if name.startswith("custom_column_") or name.startswith("books_custom_column_"): if name.startswith("custom_column_") or name.startswith("books_custom_column_"):
if table is not None: if table is not None:
Base.metadata.remove(table) Base.metadata.remove(table)
def reconnect_db(config):
session.close()
engine.dispose()
setup_db(config)

View File

@ -276,7 +276,7 @@ def feed_languages(book_id):
isoLanguages.get(part3=entry.languages[index].lang_code).name)''' isoLanguages.get(part3=entry.languages[index].lang_code).name)'''
return render_xml_template('feed.xml', entries=entries, pagination=pagination) return render_xml_template('feed.xml', entries=entries, pagination=pagination)
@opds.route("/opds/shelfindex/", defaults={'public': 0}) @opds.route("/opds/shelfindex", defaults={'public': 0})
@opds.route("/opds/shelfindex/<string:public>") @opds.route("/opds/shelfindex/<string:public>")
@requires_basic_auth_if_no_ano @requires_basic_auth_if_no_ano
def feed_shelfindex(public): def feed_shelfindex(public):
@ -378,15 +378,16 @@ def render_xml_template(*args, **kwargs):
def feed_get_cover(book_id): def feed_get_cover(book_id):
return get_book_cover(book_id) return get_book_cover(book_id)
@opds.route("/opds/readbooks/") @opds.route("/opds/readbooks")
@requires_basic_auth_if_no_ano @requires_basic_auth_if_no_ano
def feed_read_books(): def feed_read_books():
off = request.args.get("offset") or 0 off = request.args.get("offset") or 0
return render_read_books(int(off) / (int(config.config_books_per_page)) + 1, True, True) result, pagination = render_read_books(int(off) / (int(config.config_books_per_page)) + 1, True, True)
return render_xml_template('feed.xml', entries=result, pagination=pagination)
@opds.route("/opds/unreadbooks")
@opds.route("/opds/unreadbooks/")
@requires_basic_auth_if_no_ano @requires_basic_auth_if_no_ano
def feed_unread_books(): def feed_unread_books():
off = request.args.get("offset") or 0 off = request.args.get("offset") or 0
return render_read_books(int(off) / (int(config.config_books_per_page)) + 1, False, True) result, pagination = render_read_books(int(off) / (int(config.config_books_per_page)) + 1, False, True)
return render_xml_template('feed.xml', entries=result, pagination=pagination)

View File

@ -43,7 +43,7 @@ from werkzeug.exceptions import default_exceptions
from werkzeug.datastructures import Headers from werkzeug.datastructures import Headers
from werkzeug.security import generate_password_hash, check_password_hash from werkzeug.security import generate_password_hash, check_password_hash
from . import constants, logger, isoLanguages, services, worker from . import constants, config, logger, isoLanguages, services, worker
from . import searched_ids, lm, babel, db, ub, config, get_locale, app from . import searched_ids, lm, babel, db, ub, config, get_locale, app
from .gdriveutils import getFileFromEbooksFolder, do_gdrive_download from .gdriveutils import getFileFromEbooksFolder, do_gdrive_download
from .helper import common_filters, get_search_results, fill_indexpage, speaking_language, check_valid_domain, \ from .helper import common_filters, get_search_results, fill_indexpage, speaking_language, check_valid_domain, \
@ -93,12 +93,11 @@ def error_http(error):
def internal_error(error): def internal_error(error):
__, __, tb = sys.exc_info()
return render_template('http_error.html', return render_template('http_error.html',
error_code="Internal Server Error", error_code="Internal Server Error",
error_name=str(error), error_name=str(error),
issue=True, issue=True,
error_stack=traceback.format_tb(tb), error_stack=traceback.format_exc().split("\n"),
instance=config.config_calibre_web_title instance=config.config_calibre_web_title
), 500 ), 500
@ -791,9 +790,7 @@ def get_tasks_status():
@app.route("/reconnect") @app.route("/reconnect")
def reconnect(): def reconnect():
db.session.close() db.reconnect_db(config)
db.engine.dispose()
db.setup_db()
return json.dumps({}) return json.dumps({})
@web.route("/search", methods=["GET"]) @web.route("/search", methods=["GET"])
@ -985,10 +982,7 @@ def render_read_books(page, are_read, as_xml=False, order=None):
entries, random, pagination = fill_indexpage(page, db.Books, db_filter, order) entries, random, pagination = fill_indexpage(page, db.Books, db_filter, order)
if as_xml: if as_xml:
xml = render_title_template('feed.xml', entries=entries, pagination=pagination) return entries, pagination
response = make_response(xml)
response.headers["Content-Type"] = "application/xml; charset=utf-8"
return response
else: else:
if are_read: if are_read:
name = _(u'Read Books') + ' (' + str(len(readBookIds)) + ')' name = _(u'Read Books') + ' (' + str(len(readBookIds)) + ')'

View File

@ -231,7 +231,7 @@ class WorkerThread(threading.Thread):
self.queue.pop(index) self.queue.pop(index)
self.UIqueue.pop(index) self.UIqueue.pop(index)
# if we are deleting entries before the current index, adjust the index # if we are deleting entries before the current index, adjust the index
if index <= self.current and index: if index <= self.current and self.current:
self.current -= 1 self.current -= 1
self.last = len(self.queue) self.last = len(self.queue)

File diff suppressed because it is too large Load Diff