From d770e5392ee43789d51fcdbece4ad9f2c9f75d4c Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Wed, 6 Apr 2022 11:12:57 +0200 Subject: [PATCH 1/6] Further fix for #2363 --- cps/metadata_provider/lubimyczytac.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cps/metadata_provider/lubimyczytac.py b/cps/metadata_provider/lubimyczytac.py index 90a6b2d8..4a77f4ea 100644 --- a/cps/metadata_provider/lubimyczytac.py +++ b/cps/metadata_provider/lubimyczytac.py @@ -125,6 +125,7 @@ class LubimyCzytac(Metadata): ) return final_matches return matches + return [] def _prepare_query(self, title: str) -> str: query = "" From 1136383b9a2d0787018ff245f174a7f914cc8b4a Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Mon, 11 Apr 2022 19:15:50 +0200 Subject: [PATCH 2/6] Bugfix for cli folder names as -p or -g parameters --- cps/__init__.py | 4 ++-- cps/cli.py | 13 ++++++++++--- cps/constants.py | 2 ++ cps/gdriveutils.py | 11 ++++------- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/cps/__init__.py b/cps/__init__.py index 0b912d23..62e45e72 100644 --- a/cps/__init__.py +++ b/cps/__init__.py @@ -91,7 +91,7 @@ if wtf_present: else: csrf = None -ub.init_db(cli.settingspath) +ub.init_db(cli.settings_path) # pylint: disable=no-member config = config_sql.load_configuration(ub.session) @@ -106,7 +106,7 @@ log = logger.create() from . import services db.CalibreDB.update_config(config) -db.CalibreDB.setup_db(config.config_calibre_dir, cli.settingspath) +db.CalibreDB.setup_db(config.config_calibre_dir, cli.settings_path) calibre_db = db.CalibreDB() diff --git a/cps/cli.py b/cps/cli.py index 36c03513..629fd76d 100644 --- a/cps/cli.py +++ b/cps/cli.py @@ -24,7 +24,7 @@ import socket from .constants import CONFIG_DIR as _CONFIG_DIR from .constants import STABLE_VERSION as _STABLE_VERSION from .constants import NIGHTLY_VERSION as _NIGHTLY_VERSION - +from .constants import DEFAULT_SETTINGS_FILE, DEFAULT_GDRIVE_FILE def version_info(): if _NIGHTLY_VERSION[1].startswith('$Format'): @@ -51,8 +51,15 @@ parser.add_argument('-d', action='store_true', help='Dry run of updater to check parser.add_argument('-r', action='store_true', help='Enable public database reconnect route under /reconnect') args = parser.parse_args() -settingspath = args.p or os.path.join(_CONFIG_DIR, "app.db") -gdpath = args.g or os.path.join(_CONFIG_DIR, "gdrive.db") +settings_path = args.p or os.path.join(_CONFIG_DIR, DEFAULT_SETTINGS_FILE) +gd_path = args.g or os.path.join(_CONFIG_DIR, DEFAULT_GDRIVE_FILE) + +if os.path.isdir(settings_path): + settings_path = os.path.join(settings_path, DEFAULT_SETTINGS_FILE) + +if os.path.isdir(gd_path): + gd_path = os.path.join(gd_path, DEFAULT_GDRIVE_FILE) + # handle and check parameter for ssl encryption certfilepath = None diff --git a/cps/constants.py b/cps/constants.py index f40d16b0..57c98be1 100644 --- a/cps/constants.py +++ b/cps/constants.py @@ -43,6 +43,8 @@ if HOME_CONFIG: else: CONFIG_DIR = os.environ.get('CALIBRE_DBPATH', BASE_DIR) +DEFAULT_SETTINGS_FILE = "app.db" +DEFAULT_GDRIVE_FILE = "gdrive.db" ROLE_USER = 0 << 0 ROLE_ADMIN = 1 << 0 diff --git a/cps/gdriveutils.py b/cps/gdriveutils.py index 6073777e..ee8ee953 100644 --- a/cps/gdriveutils.py +++ b/cps/gdriveutils.py @@ -35,10 +35,6 @@ except ImportError: from sqlalchemy.exc import OperationalError, InvalidRequestError, IntegrityError from sqlalchemy.sql.expression import text -#try: -# from six import __version__ as six_version -#except ImportError: -# six_version = "not installed" try: from httplib2 import __version__ as httplib2_version except ImportError: @@ -141,11 +137,12 @@ class Gdrive: def __init__(self): self.drive = getDrive(gauth=Gauth.Instance().auth) + def is_gdrive_ready(): return os.path.exists(SETTINGS_YAML) and os.path.exists(CREDENTIALS) -engine = create_engine('sqlite:///{0}'.format(cli.gdpath), echo=False) +engine = create_engine('sqlite:///{0}'.format(cli.gd_path), echo=False) Base = declarative_base() # Open session for database connection @@ -193,11 +190,11 @@ def migrate(): session.execute('ALTER TABLE gdrive_ids2 RENAME to gdrive_ids') break -if not os.path.exists(cli.gdpath): +if not os.path.exists(cli.gd_path): try: Base.metadata.create_all(engine) except Exception as ex: - log.error("Error connect to database: {} - {}".format(cli.gdpath, ex)) + log.error("Error connect to database: {} - {}".format(cli.gd_path, ex)) raise migrate() From 652d0fd86faac32680444c96d57327fd29c8a7b8 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Mon, 11 Apr 2022 19:40:43 +0200 Subject: [PATCH 3/6] Update google-api-python-client version --- optional-requirements.txt | 4 ++-- setup.cfg | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/optional-requirements.txt b/optional-requirements.txt index 208d889d..fea410e5 100644 --- a/optional-requirements.txt +++ b/optional-requirements.txt @@ -1,5 +1,5 @@ # GDrive Integration -google-api-python-client>=1.7.11,<2.43.0 +google-api-python-client>=1.7.11,<2.44.0 gevent>20.6.0,<22.0.0 greenlet>=0.4.17,<1.2.0 httplib2>=0.9.2,<0.21.0 @@ -13,7 +13,7 @@ rsa>=3.4.2,<4.9.0 # Gmail google-auth-oauthlib>=0.4.3,<0.6.0 -google-api-python-client>=1.7.11,<2.43.0 +google-api-python-client>=1.7.11,<2.44.0 # goodreads goodreads>=0.3.2,<0.4.0 diff --git a/setup.cfg b/setup.cfg index 49496fc9..e9c23604 100644 --- a/setup.cfg +++ b/setup.cfg @@ -61,7 +61,7 @@ install_requires = [options.extras_require] gdrive = - google-api-python-client>=1.7.11,<2.43.0 + google-api-python-client>=1.7.11,<2.44.0 gevent>20.6.0,<22.0.0 greenlet>=0.4.17,<1.2.0 httplib2>=0.9.2,<0.21.0 @@ -74,7 +74,7 @@ gdrive = rsa>=3.4.2,<4.9.0 gmail = google-auth-oauthlib>=0.4.3,<0.6.0 - google-api-python-client>=1.7.11,<2.43.0 + google-api-python-client>=1.7.11,<2.44.0 goodreads = goodreads>=0.3.2,<0.4.0 python-Levenshtein>=0.12.0,<0.13.0 From 028e6855a71bb064ffc5a8b34cd240e5e5442c06 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Tue, 12 Apr 2022 18:45:06 +0200 Subject: [PATCH 4/6] Pagination button disapears in standard theme once infinite scroll is triggered --- cps/static/js/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cps/static/js/main.js b/cps/static/js/main.js index b18cf229..91084f06 100755 --- a/cps/static/js/main.js +++ b/cps/static/js/main.js @@ -381,8 +381,8 @@ $(function() { //extraScrollPx: 300 }); $loadMore.on( "append.infiniteScroll", function( event, response, path, data ) { + $(".pagination").addClass("hidden").html(() => $(response).find(".pagination").html()); if ($("body").hasClass("blur")) { - $(".pagination").addClass("hidden").html(() => $(response).find(".pagination").html()); $(" a:not(.dropdown-toggle) ") .removeAttr("data-toggle"); } From 83b99fcb1a6fc60a81023fec835e22883c2a903e Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Tue, 12 Apr 2022 19:33:00 +0200 Subject: [PATCH 5/6] Fix cover upload url with spaces at the end Support image/jpg as upload format mimetype, remove redundant check of mimetype --- cps/editbooks.py | 2 +- cps/helper.py | 30 ++++++++++++++++-------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/cps/editbooks.py b/cps/editbooks.py index c07e5d24..ab2bd55e 100755 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -810,7 +810,7 @@ def edit_book(book_id): if to_save["cover_url"].endswith('/static/generic_cover.jpg'): book.has_cover = 0 else: - result, error = helper.save_cover_from_url(to_save["cover_url"], book.path) + result, error = helper.save_cover_from_url(to_save["cover_url"].strip(), book.path) if result is True: book.has_cover = 1 modify_date = True diff --git a/cps/helper.py b/cps/helper.py index 5d5cc021..69b3e2f8 100644 --- a/cps/helper.py +++ b/cps/helper.py @@ -753,6 +753,9 @@ def save_cover_from_url(url, book_path): log.error("python modul advocate is not installed but is needed") return False, _("Python modul 'advocate' is not installed but is needed for cover downloads") img.raise_for_status() + # # cover_processing() + # move_coverfile(meta, db_book) + return save_cover(img, book_path) except (socket.gaierror, requests.exceptions.HTTPError, @@ -802,24 +805,23 @@ def save_cover(img, book_path): content_type = img.headers.get('content-type') if use_IM: - if content_type not in ('image/jpeg', 'image/png', 'image/webp', 'image/bmp'): + if content_type not in ('image/jpeg', 'image/jpg', 'image/png', 'image/webp', 'image/bmp'): log.error("Only jpg/jpeg/png/webp/bmp files are supported as coverfile") return False, _("Only jpg/jpeg/png/webp/bmp files are supported as coverfile") # convert to jpg because calibre only supports jpg - if content_type != 'image/jpg': - try: - if hasattr(img, 'stream'): - imgc = Image(blob=img.stream) - else: - imgc = Image(blob=io.BytesIO(img.content)) - imgc.format = 'jpeg' - imgc.transform_colorspace("rgb") - img = imgc - except (BlobError, MissingDelegateError): - log.error("Invalid cover file content") - return False, _("Invalid cover file content") + try: + if hasattr(img, 'stream'): + imgc = Image(blob=img.stream) + else: + imgc = Image(blob=io.BytesIO(img.content)) + imgc.format = 'jpeg' + imgc.transform_colorspace("rgb") + img = imgc + except (BlobError, MissingDelegateError): + log.error("Invalid cover file content") + return False, _("Invalid cover file content") else: - if content_type not in 'image/jpeg': + if content_type not in ['image/jpeg', 'image/jpg']: log.error("Only jpg/jpeg files are supported as coverfile") return False, _("Only jpg/jpeg files are supported as coverfile") From df53a5d8c97fe6790f75ed1d9e073b5f614dfc01 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Wed, 13 Apr 2022 18:37:23 +0200 Subject: [PATCH 6/6] Prevent none comment while upload pdf documents --- cps/uploader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cps/uploader.py b/cps/uploader.py index 992d188c..6aa811be 100644 --- a/cps/uploader.py +++ b/cps/uploader.py @@ -231,7 +231,7 @@ def pdf_meta(tmp_file_path, original_file_name, original_file_extension): if title == '': title = doc_info.title if doc_info.title else original_file_name if subject == '': - subject = doc_info.subject + subject = doc_info.subject or "" if tags == '' and '/Keywords' in doc_info: if isinstance(doc_info['/Keywords'], bytes): tags = doc_info['/Keywords'].decode('utf-8')