janeczku / calibre-web

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

Download URL blocked by Kobo's experimental browser #2990

Open WesleyHilhorst opened 5 months ago

WesleyHilhorst commented 5 months ago

Describe the bug/problem

It seems Kobo has added an extra requirement to successfully download a kepub file. As is known, the file downloading should end with .epub. Now not only the Content-Disposition header should be changed, but it seems that also the file path seems to be required to link to a filename the browser can download.

Possible fix

I am not a Python/Flask/Jinja developer, but I have found a workaround which works for my case. I am pretty sure it wouldn't be a "correct" fix for the general codebase. I am sure a seasoned Python developer can fix this in no-time at all :-).

My fix is changing the detail.html template. Wherever a download URL is created, I append the .epub in case the kepub format is used. In general, I can see it doesn't really matter what is put in the last part of the download URL for the inner workings of calibre-web since the route does not use this part of the path.

The change would be:

<a href="{{ url_for('web.download_link', book_id=entry.id, book_format=format.format|lower, anyname=entry.id|string+'.'+format.format|lower) }}"

To

<a href="{{ url_for('web.download_link', book_id=entry.id, book_format=format.format|lower, anyname=entry.id|string+'.'+format.format|lower|replace('kepub', 'kepub.epub')) }}"

To reproduce the problem

Steps to reproduce the behavior:

  1. Go to the experimental web browser on Kobo
  2. Find a kepub formatted file
  3. Try to download
  4. Nothing happens due to the browser not wanting to download the file