From 7992b221504fa25ff7f80c0b1e5fbf9b30315381 Mon Sep 17 00:00:00 2001 From: Connor Demille Date: Thu, 14 Mar 2024 13:05:40 -0400 Subject: [PATCH 1/7] 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 86e59317..89f1b463 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 8176bf41..e8864cc7 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 d5fe580c..b52ba7e7 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 8035d03f..4476b6f9 100755 --- a/cps/templates/config_edit.html +++ b/cps/templates/config_edit.html @@ -111,6 +111,14 @@ +
+ + +
From 2c37730c9ccaf649ceeafdf1526b2b6147ee6aca Mon Sep 17 00:00:00 2001 From: Connor Demille Date: Thu, 14 Mar 2024 20:52:55 -0400 Subject: [PATCH 2/7] Fix typo --- cps/editbooks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cps/editbooks.py b/cps/editbooks.py index b52ba7e7..ce07e8ca 100644 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -308,7 +308,7 @@ def upload(): 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() + config.config_auto_convert_to_format.upper() != book_format_from ): book_format_to = config.config_auto_convert_to_format.upper() rtn = helper.convert_book_format(book_id, From 84fe4f225d5297117df34946057bde231b1be5e7 Mon Sep 17 00:00:00 2001 From: Connor Demille Date: Thu, 14 Mar 2024 20:58:41 -0400 Subject: [PATCH 3/7] Add option to disable auto-conversion --- cps/templates/config_edit.html | 1 + 1 file changed, 1 insertion(+) diff --git a/cps/templates/config_edit.html b/cps/templates/config_edit.html index 4476b6f9..3b4a41e1 100755 --- a/cps/templates/config_edit.html +++ b/cps/templates/config_edit.html @@ -114,6 +114,7 @@
{% for format in config.config_upload_formats.split(",") %} From d19885cbbe95c1349e257338e1570d440ce28c03 Mon Sep 17 00:00:00 2001 From: Connor Demille Date: Thu, 14 Mar 2024 21:52:32 -0400 Subject: [PATCH 5/7] Fix config dropdown 'Disabled' selection --- cps/templates/config_edit.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cps/templates/config_edit.html b/cps/templates/config_edit.html index 075ef3f5..1a3be3b0 100755 --- a/cps/templates/config_edit.html +++ b/cps/templates/config_edit.html @@ -114,7 +114,7 @@
{% for format in config.config_upload_formats.split(",") %} - + {% endfor %}
From 7c133bf5c1ec7853ff5f09c1b1acff7cecced3bd Mon Sep 17 00:00:00 2001 From: Connor Demille Date: Tue, 30 Apr 2024 16:33:12 -0400 Subject: [PATCH 7/7] Accept multiple types for auto-conversion --- cps/admin.py | 2 +- cps/config_sql.py | 2 +- cps/editbooks.py | 32 ++++++++++++++++---------------- cps/templates/config_edit.html | 9 ++------- 4 files changed, 20 insertions(+), 25 deletions(-) diff --git a/cps/admin.py b/cps/admin.py index 89f1b463..d6a9edf7 100755 --- a/cps/admin.py +++ b/cps/admin.py @@ -1772,7 +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") + _config_string(to_save, "config_auto_convert_to_formats") 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 e8864cc7..7d09945d 100644 --- a/cps/config_sql.py +++ b/cps/config_sql.py @@ -144,7 +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_auto_convert_to_formats = 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 ce07e8ca..d6d8497b 100644 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -306,22 +306,22 @@ def upload(): 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() != book_format_from - ): - 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 (config.config_auto_convert_to_formats): + for format in config.config_auto_convert_to_formats.split(','): + book_format_to = format.strip().upper() + if book_format_to == book_format_from: + continue + 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(): diff --git a/cps/templates/config_edit.html b/cps/templates/config_edit.html index bc8c1655..e4ff41cc 100755 --- a/cps/templates/config_edit.html +++ b/cps/templates/config_edit.html @@ -112,13 +112,8 @@
- - + +