Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto convert on upload #3019

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cps/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions cps/config_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions cps/editbooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down
10 changes: 5 additions & 5 deletions cps/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion cps/static/js/password.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
8 changes: 8 additions & 0 deletions cps/templates/config_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ <h4 class="panel-title">
<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>
Expand Down