janeczku / calibre-web

:books: Web app for browsing, reading and downloading eBooks stored in a Calibre database
GNU General Public License v3.0
12.69k stars 1.33k forks source link

Add configurable auto-conversion on upload #3020

Open subtlepseudonym opened 6 months ago

subtlepseudonym commented 6 months ago

Add configurable auto-conversion on upload

This change adds a step to the upload process that kicks off a conversion task if config_auto_convert_to_format is set to a valid format. To make configuring this relatively easy, a dropdown has been added to Basic Configuration>Feature Configuration, populated by Allowed Upload Fileformats.

It's been noted in an issue comment that this functionality may be slated for eventual inclusion as a plugin rather than the implementation given in this patch. If that's the case, I'm happy to close this PR.

Relevant Issues

marie6324 commented 5 months ago

Hey, I'm trying to implement this on my existing install and keep getting the below. Running current master under the linuxservers docker image. Any thoughts?

[2024-04-19 10:30:25,902] ERROR {cps:1414} Exception on /admin/config [GET]
Traceback (most recent call last):
  File "/lsiopy/lib/python3.10/site-packages/flask/app.py", line 2190, in wsgi_app
    response = self.full_dispatch_request()
  File "/lsiopy/lib/python3.10/site-packages/flask/app.py", line 1486, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/lsiopy/lib/python3.10/site-packages/flask/app.py", line 1484, in full_dispatch_request
    rv = self.dispatch_request()
  File "/lsiopy/lib/python3.10/site-packages/flask/app.py", line 1469, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "/lsiopy/lib/python3.10/site-packages/flask_login/utils.py", line 290, in decorated_view
    return current_app.ensure_sync(func)(*args, **kwargs)
  File "/app/calibre-web/cps/admin.py", line 98, in inner
    return f(*args, **kwargs)
  File "/app/calibre-web/cps/admin.py", line 248, in configuration
    return render_title_template("config_edit.html",
  File "/app/calibre-web/cps/render_template.py", line 114, in render_title_template
    return render_template(instance=config.config_calibre_web_title, sidebar=sidebar, simple=simple,
  File "/lsiopy/lib/python3.10/site-packages/flask/templating.py", line 151, in render_template
    return _render(app, template, context)
  File "/lsiopy/lib/python3.10/site-packages/flask/templating.py", line 132, in _render
    rv = template.render(context)
  File "/lsiopy/lib/python3.10/site-packages/jinja2/environment.py", line 1301, in render
    self.environment.handle_exception()
  File "/lsiopy/lib/python3.10/site-packages/jinja2/environment.py", line 936, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "/app/calibre-web/cps/templates/config_edit.html", line 1, in top-level template code
    {% extends "layout.html" %}
  File "/app/calibre-web/cps/templates/layout.html", line 167, in top-level template code
    {% block body %}{% endblock %}
  File "/app/calibre-web/cps/templates/config_edit.html", line 119, in block 'body'
    <option value="{{ format }}"{% if config.config_auto_convert_to_format.lower() == format.lower() %} selected{% endif %}>{{ format }}</option>
  File "/lsiopy/lib/python3.10/site-packages/jinja2/utils.py", line 83, in from_obj
    if hasattr(obj, "jinja_pass_arg"):
jinja2.exceptions.UndefinedError: 'None' has no attribute 'lower'
subtlepseudonym commented 5 months ago

Hey, I'm trying to implement this on my existing install and keep getting the below. Running current master under the linuxservers docker image. Any thoughts?

Looks like I missed the case where the new config is unset. 665056c should cover it.

marie6324 commented 5 months ago

That looks to have resolved it! Thanks for the quick turnaround.

Any thoughts on potentially allowing the convert formats to be a multiple choice? Example is Kindle and iBooks where the former wants MOBI while the latter (appears to) perform(s) better with EPUB.

subtlepseudonym commented 5 months ago

Any thoughts on potentially allowing the convert formats to be a multiple choice? Example is Kindle and iBooks where the former wants MOBI while the latter (appears to) perform(s) better with EPUB.

Sorry for leaving you on read so long. I've updated the config field to accept a comma-delimited list of formats. I tested with auto-conversion to epub and pdf (from mobi) on my system and both jobs queued successfully.

marie6324 commented 4 months ago

Confirmed that this works, and works beautifully. Now we just need to get it merged in. hint hint maintainers :)

marie6324 commented 4 weeks ago

@OzzieIsaacs I've been using this feature for a couple months now without issue. What would it take to get the PR merged into master, or at least a feature branch parallel to the current master?