From fcc95bd8953c0b1c00c7af1dfd2f3bb3b3c9dbd0 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sun, 10 Mar 2024 16:39:06 +0100 Subject: [PATCH 1/2] Improvements for password verify (addresses: https://github.com/iiab/calibre-web/pull/138) --- cps/helper.py | 10 +++++----- cps/static/js/password.js | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cps/helper.py b/cps/helper.py index 92aa081ee0..e6d56bf6ae 100644 --- a/cps/helper.py +++ b/cps/helper.py @@ -696,15 +696,15 @@ def valid_password(check_password): if config.config_password_min_length > 0: verify += r"^(?=.{" + str(config.config_password_min_length) + ",}$)" if config.config_password_number: - verify += "(?=.*?\d)" + verify += r"(?=.*?\d)" if config.config_password_lower: - verify += "(?=.*?[\p{Ll}])" + verify += r"(?=.*?[\p{Ll}])" if config.config_password_upper: - verify += "(?=.*?[\p{Lu}])" + verify += r"(?=.*?[\p{Lu}])" if config.config_password_character: - verify += "(?=.*?[\p{Letter}])" + verify += r"(?=.*?[\p{Letter}])" if config.config_password_special: - verify += "(?=.*?[^\p{Letter}\s0-9])" + verify += r"(?=.*?[^\p{Letter}\s0-9])" match = regex.match(verify, check_password) if not match: raise Exception(_("Password doesn't comply with password validation rules")) diff --git a/cps/static/js/password.js b/cps/static/js/password.js index 5d640d29d8..2a6f1cda12 100644 --- a/cps/static/js/password.js +++ b/cps/static/js/password.js @@ -24,7 +24,7 @@ $(document).ready(function() { }, }, function () { - if ($('#password').data("verify")) { + if ($('#password').data("verify") === "True") { // Initialized and ready to go var options = {}; options.common = { From de40f75be53fbb76a1ea93951609b920ec037724 Mon Sep 17 00:00:00 2001 From: Connor Demille Date: Thu, 14 Mar 2024 13:05:40 -0400 Subject: [PATCH 2/2] Add configurable auto-conversion on upload --- cps/admin.py | 1 + cps/config_sql.py | 1 + cps/editbooks.py | 18 ++++++++++++++++++ cps/templates/config_edit.html | 8 ++++++++ 4 files changed, 28 insertions(+) diff --git a/cps/admin.py b/cps/admin.py index 86e5931779..89f1b463d1 100755 --- a/cps/admin.py +++ b/cps/admin.py @@ -1772,6 +1772,7 @@ def _configuration_update_helper(): reboot_required |= _config_checkbox_int(to_save, "config_kobo_sync") _config_int(to_save, "config_external_port") _config_checkbox_int(to_save, "config_kobo_proxy") + _config_string(to_save, "config_auto_convert_to_format") if "config_upload_formats" in to_save: to_save["config_upload_formats"] = ','.join( diff --git a/cps/config_sql.py b/cps/config_sql.py index 8176bf41aa..e8864cc765 100644 --- a/cps/config_sql.py +++ b/cps/config_sql.py @@ -144,6 +144,7 @@ class _Settings(_Base): config_binariesdir = Column(String, default=None) config_calibre = Column(String) config_rarfile_location = Column(String, default=None) + config_auto_convert_to_format = Column(String, default=None) config_upload_formats = Column(String, default=','.join(constants.EXTENSIONS_UPLOAD)) config_unicode_filename = Column(Boolean, default=False) config_embed_metadata = Column(Boolean, default=True) diff --git a/cps/editbooks.py b/cps/editbooks.py index d5fe580c10..b52ba7e7c7 100644 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -305,6 +305,24 @@ def upload(): WorkerThread.add(current_user.name, TaskUpload(upload_text, escape(title))) helper.add_book_to_thumbnail_cache(book_id) + book_format_from = meta.extension.upper()[1:] + if ( + config.config_auto_convert_to_format and + config.config_auto_convert_to_format.upper() != meta.extension.lower() + ): + book_format_to = config.config_auto_convert_to_format.upper() + rtn = helper.convert_book_format(book_id, + config.get_book_path(), + book_format_from, + book_format_to, + current_user.name) + if rtn is None: + flash(_("Book successfully queued for converting to %(book_format)s", + book_format=book_format_to), + category="success") + else: + flash(_("There was an error converting this book: %(res)s", res=rtn), category="error") + if len(request.files.getlist("btn-upload")) < 2: if current_user.role_edit() or current_user.role_admin(): resp = {"location": url_for('edit-book.show_edit_book', book_id=book_id)} diff --git a/cps/templates/config_edit.html b/cps/templates/config_edit.html index 8035d03f05..4476b6f90b 100755 --- a/cps/templates/config_edit.html +++ b/cps/templates/config_edit.html @@ -111,6 +111,14 @@

+
+ + +