From f498fec4e1ae4d0c90fab0fb88eb3b2b27d2af45 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 1 Oct 2017 17:13:00 +0200 Subject: [PATCH 1/8] added metadata.db in case one uses a local copy for debugging --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 15411480..7f7ae5f5 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,5 @@ settings.yaml gdrive_credentials vendor + +metadata.db From 70d093b19351c7244b3fbb02ef39573923ed5d1a Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 1 Oct 2017 17:14:20 +0200 Subject: [PATCH 2/8] unicode gave an NameError with python3 --- cps/ub.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cps/ub.py b/cps/ub.py index a559db43..3d589c64 100644 --- a/cps/ub.py +++ b/cps/ub.py @@ -6,6 +6,7 @@ from sqlalchemy import exc from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import * from flask_login import AnonymousUserMixin +import sys import os import logging from werkzeug.security import generate_password_hash @@ -387,7 +388,11 @@ class Config: (self.config_default_role & ROLE_DELETE_BOOKS == ROLE_DELETE_BOOKS)) def mature_content_tags(self): - return list(map(unicode.lstrip, self.config_mature_content_tags.split(","))) + if (sys.version_info > (3, 0)): #Python3 str, Python2 unicode + lstrip = str.lstrip + else: + lstrip = unicode.lstrip + return list(map(lstrip, self.config_mature_content_tags.split(","))) def get_Log_Level(self): ret_value="" From 7ddfa1881be4aee0fc832a3aef8b2a8234029130 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 1 Oct 2017 17:15:44 +0200 Subject: [PATCH 3/8] added FB2 mime type --- cps/web.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cps/web.py b/cps/web.py index 5873bad8..70903812 100755 --- a/cps/web.py +++ b/cps/web.py @@ -203,6 +203,7 @@ class ReverseProxied(object): mimetypes.init() mimetypes.add_type('application/xhtml+xml', '.xhtml') mimetypes.add_type('application/epub+zip', '.epub') +mimetypes.add_type('application/fb2+zip', '.fb2') mimetypes.add_type('application/x-mobipocket-ebook', '.mobi') mimetypes.add_type('application/x-mobipocket-ebook', '.prc') mimetypes.add_type('application/vnd.amazon.ebook', '.azw') From d336f9faa6fdf0bd932c44441e80dcd748b1e0d4 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 1 Oct 2017 17:16:57 +0200 Subject: [PATCH 4/8] fixed OPDS templates --- Descript.ion | 1 + cps/templates/feed.xml | 3 +-- cps/templates/index.xml | 27 +++++++++------------------ 3 files changed, 11 insertions(+), 20 deletions(-) create mode 100644 Descript.ion diff --git a/Descript.ion b/Descript.ion new file mode 100644 index 00000000..cd5434bb --- /dev/null +++ b/Descript.ion @@ -0,0 +1 @@ +cps zexit() diff --git a/cps/templates/feed.xml b/cps/templates/feed.xml index 6f79a3aa..fce047d9 100644 --- a/cps/templates/feed.xml +++ b/cps/templates/feed.xml @@ -64,8 +64,7 @@ {{entry.name}} {{ url_for(folder, book_id=entry.id) }} - - + {% endfor %} diff --git a/cps/templates/index.xml b/cps/templates/index.xml index 228637c2..66e32a69 100644 --- a/cps/templates/index.xml +++ b/cps/templates/index.xml @@ -12,64 +12,55 @@ {{_('Hot Books')}} - - + {{url_for('feed_hot')}} {{_('Popular publications from this catalog based on Downloads.')}} {{_('Best rated Books')}} - - + {{url_for('feed_best_rated')}} {{_('Popular publications from this catalog based on Rating.')}} {{_('New Books')}} - - + {{url_for('feed_new')}} {{_('The latest Books')}} {{_('Random Books')}} - - + {{url_for('feed_discover')}} {{_('Show Random Books')}} {{_('Read Books')}} - - + {{url_for('feed_read_books')}} {{_('Read Books')}} {{_('Unread Books')}} - - + {{url_for('feed_unread_books')}} {{_('Unread Books')}} {{_('Authors')}} - - + {{url_for('feed_authorindex')}} {{_('Books ordered by Author')}} {{_('Category list')}} - - + {{url_for('feed_categoryindex')}} {{_('Books ordered by category')}} {{_('Series list')}} - - + {{url_for('feed_seriesindex')}} {{_('Books ordered by series')}} From 3c9f8b151d299f316469661c425380f9cce679a0 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 1 Oct 2017 18:41:19 +0200 Subject: [PATCH 5/8] added check for anonymous session in read_books, otherwise current_user.id is not defined --- cps/web.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/cps/web.py b/cps/web.py index 70903812..c35d978e 100755 --- a/cps/web.py +++ b/cps/web.py @@ -1713,15 +1713,21 @@ def feed_get_cover(book_id): def render_read_books(page, are_read, as_xml=False): - readBooks = ub.session.query(ub.ReadBook).filter(ub.ReadBook.user_id == int(current_user.id)).filter(ub.ReadBook.is_read == True).all() - readBookIds = [x.book_id for x in readBooks] - if are_read: - db_filter = db.Books.id.in_(readBookIds) - else: - db_filter = ~db.Books.id.in_(readBookIds) + if not current_user.is_anonymous(): + readBooks = ub.session.query(ub.ReadBook).filter(ub.ReadBook.user_id == int(current_user.id)).filter(ub.ReadBook.is_read == True).all() + readBookIds = [x.book_id for x in readBooks] + if are_read: + db_filter = db.Books.id.in_(readBookIds) + else: + db_filter = ~db.Books.id.in_(readBookIds) + + entries, random, pagination = fill_indexpage(page, db.Books, + db_filter, db.Books.timestamp.desc()) + else: + entries = [] + random = False + pagination = Pagination(page, 1, 0) - entries, random, pagination = fill_indexpage(page, db.Books, - db_filter, db.Books.timestamp.desc()) if as_xml: xml = render_title_template('feed.xml', entries=entries, pagination=pagination) response = make_response(xml) From 1ada1704b0ddd12bd6a9299671953df0196cc557 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 1 Oct 2017 18:42:35 +0200 Subject: [PATCH 6/8] excluded read/unread when exposing the catalog to an anonymous user --- cps/templates/index.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cps/templates/index.xml b/cps/templates/index.xml index 66e32a69..f0a6e2e0 100644 --- a/cps/templates/index.xml +++ b/cps/templates/index.xml @@ -34,6 +34,7 @@ {{url_for('feed_discover')}} {{_('Show Random Books')}} +{% if not current_user.is_anonymous() %} {{_('Read Books')}} @@ -46,6 +47,7 @@ {{url_for('feed_unread_books')}} {{_('Unread Books')}} +{% endif %} {{_('Authors')}} From 0f0c6dde09c950c313930220def5a6958ffd11a8 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 1 Oct 2017 20:24:24 +0200 Subject: [PATCH 7/8] changed application/xml to application/atom+xml --- cps/web.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/cps/web.py b/cps/web.py index c35d978e..b9f279c6 100755 --- a/cps/web.py +++ b/cps/web.py @@ -632,7 +632,7 @@ def before_request(): def feed_index(): xml = render_title_template('index.xml') response = make_response(xml) - response.headers["Content-Type"] = "application/xml" + response.headers["Content-Type"] = "application/atom+xml; charset=utf-8" return response @@ -641,7 +641,7 @@ def feed_index(): def feed_osd(): xml = render_title_template('osd.xml', lang='de-DE') response = make_response(xml) - response.headers["Content-Type"] = "application/xml" + response.headers["Content-Type"] = "application/xml; charset=utf-8" return response @@ -671,7 +671,7 @@ def feed_search(term): else: xml = render_title_template('feed.xml', searchterm="") response = make_response(xml) - response.headers["Content-Type"] = "application/xml" + response.headers["Content-Type"] = "application/atom+xml; charset=utf-8" return response @@ -685,7 +685,7 @@ def feed_new(): db.Books, True, db.Books.timestamp.desc()) xml = render_title_template('feed.xml', entries=entries, pagination=pagination) response = make_response(xml) - response.headers["Content-Type"] = "application/xml" + response.headers["Content-Type"] = "application/atom+xml; charset=utf-8" return response @@ -697,7 +697,7 @@ def feed_discover(): pagination = Pagination(1, config.config_books_per_page, int(config.config_books_per_page)) xml = render_title_template('feed.xml', entries=entries, pagination=pagination) response = make_response(xml) - response.headers["Content-Type"] = "application/xml" + response.headers["Content-Type"] = "application/atom+xml; charset=utf-8" return response @@ -711,7 +711,7 @@ def feed_best_rated(): db.Books, db.Books.ratings.any(db.Ratings.rating > 9), db.Books.timestamp.desc()) xml = render_title_template('feed.xml', entries=entries, pagination=pagination) response = make_response(xml) - response.headers["Content-Type"] = "application/xml" + response.headers["Content-Type"] = "application/atom+xml; charset=utf-8" return response @@ -739,7 +739,7 @@ def feed_hot(): pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page, numBooks) xml = render_title_template('feed.xml', entries=entries, pagination=pagination) response = make_response(xml) - response.headers["Content-Type"] = "application/xml" + response.headers["Content-Type"] = "application/atom+xml; charset=utf-8" return response @@ -755,7 +755,7 @@ def feed_authorindex(): len(db.session.query(db.Authors).all())) xml = render_title_template('feed.xml', listelements=entries, folder='feed_author', pagination=pagination) response = make_response(xml) - response.headers["Content-Type"] = "application/xml" + response.headers["Content-Type"] = "application/atom+xml; charset=utf-8" return response @@ -769,7 +769,7 @@ def feed_author(book_id): db.Books, db.Books.authors.any(db.Authors.id == book_id), db.Books.timestamp.desc()) xml = render_title_template('feed.xml', entries=entries, pagination=pagination) response = make_response(xml) - response.headers["Content-Type"] = "application/xml" + response.headers["Content-Type"] = "application/atom+xml; charset=utf-8" return response @@ -785,7 +785,7 @@ def feed_categoryindex(): len(db.session.query(db.Tags).all())) xml = render_title_template('feed.xml', listelements=entries, folder='feed_category', pagination=pagination) response = make_response(xml) - response.headers["Content-Type"] = "application/xml" + response.headers["Content-Type"] = "application/atom+xml; charset=utf-8" return response @@ -799,7 +799,7 @@ def feed_category(book_id): db.Books, db.Books.tags.any(db.Tags.id == book_id), db.Books.timestamp.desc()) xml = render_title_template('feed.xml', entries=entries, pagination=pagination) response = make_response(xml) - response.headers["Content-Type"] = "application/xml" + response.headers["Content-Type"] = "application/atom+xml; charset=utf-8" return response @@ -815,7 +815,7 @@ def feed_seriesindex(): len(db.session.query(db.Series).all())) xml = render_title_template('feed.xml', listelements=entries, folder='feed_series', pagination=pagination) response = make_response(xml) - response.headers["Content-Type"] = "application/xml" + response.headers["Content-Type"] = "application/atom+xml; charset=utf-8" return response @@ -829,7 +829,7 @@ def feed_series(book_id): db.Books, db.Books.series.any(db.Series.id == book_id),db.Books.series_index) xml = render_title_template('feed.xml', entries=entries, pagination=pagination) response = make_response(xml) - response.headers["Content-Type"] = "application/xml" + response.headers["Content-Type"] = "application/atom+xml; charset=utf-8" return response From 6855deceefecbc38292a7087e9688093fecb7b54 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 1 Oct 2017 20:48:01 +0200 Subject: [PATCH 8/8] added corresponding content-type for a downloaded book, otherwise default text/html is used --- cps/web.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cps/web.py b/cps/web.py index b9f279c6..ef44328d 100755 --- a/cps/web.py +++ b/cps/web.py @@ -874,7 +874,11 @@ def get_opds_download_link(book_id, book_format): file_name = helper.get_valid_filename(file_name) headers = Headers() headers["Content-Disposition"] = "attachment; filename*=UTF-8''%s.%s" % (quote(file_name.encode('utf8')), book_format) - app.logger.info(time.time()-startTime) + try: + headers["Content-Type"] = mimetypes.types_map['.' + book_format] + except KeyError: + headers["Content-Type"] = "application/octet-stream" + app.logger.info(time.time() - startTime) startTime = time.time() if config.config_use_google_drive: app.logger.info(time.time() - startTime)