1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-11-13 05:20:01 +00:00

Add configurable auto-conversion on upload

This commit is contained in:
Connor Demille 2024-03-14 13:05:40 -04:00
parent becb84a73d
commit 7992b22150
4 changed files with 28 additions and 0 deletions

View File

@ -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(

View File

@ -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)

View File

@ -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)}

View File

@ -111,6 +111,14 @@
<input type="checkbox" id="config_uploading" data-control="upload_settings" name="config_uploading" {% if config.config_uploading %}checked{% endif %}>
<label for="config_uploading">{{_('Enable Uploads')}} {{_('(Please ensure that users also have upload permissions)')}}</label>
</div>
<div class="form-group">
<label for="config_auto_convert_to_format">{{_('Automatically convert ebooks to format (leave blank to disable)')}}</label>
<select name="config_auto_convert_to_format" id="config_auto_convert_to_format" class="form-control">
{% for format in config.config_upload_formats.split(",") %}
<option value="{{ format }}"{% if config.config_auto_convert_to_format.lower() == format.lower() %} selected{% endif %}>{{ format }}</option>
{% endfor %}
</select>
</div>
<div data-related="upload_settings">
<div class="form-group">
<label for="config_upload_formats">{{_('Allowed Upload Fileformats')}}</label>