readium / readium-js

EPUB processing engine written in Javascript
BSD 3-Clause "New" or "Revised" License
369 stars 108 forks source link

Publication Fetcher tries loading .epub files as folders #202

Open sscheidegger opened 4 years ago

sscheidegger commented 4 years ago

Using cloud-reader-lite v.0.31.1 trying to open a packaged .epub file results in an error message "Invalid / Corrupted EPUB". Console Output shows that readium recognizes the url to be a folder instead of a packaged file: --- using PlainResourceFetcher

This is caused by an error in a Regex in js/epub-fetch/publication_fetcher.js on line 91: return !(/.epub[3?]$/.test(uriTrimmed));

Correct Regex should be: return !(/.epub[3]?$/.test(uriTrimmed));

This issue is a Bug

Expected Behaviour

Expect Ebok Urls ending on .epub to be handled as packaged EPub files and load them using ZipResourceFetcher.

Observed behaviour

Readium assumes Urls ending on .epub to be folders and tries loading them using PlainResourceFetcher, which fails.

Steps to reproduce

  1. Set up cloud-reader-lite v.0.31.1
  2. Put test.epub package in subfolder epub_content
  3. Load in Webbrowser using index.html?epub=epub_content/test.epub

Note: Problem does not occur if epub file is dragged and dropped into the browser/cloud reader.

Test file(s)

Reprocudible with any .epub file, for example moby dick

Product

sscheidegger commented 4 years ago

Btw, same Regex is being used in readium-js-viewer in: EpubLibraryOPDS.js Line 110 ReadiumViewerLite.js Line 78 ReadiumViewer.js Line 234

danielweck commented 4 years ago

In fact, /.epub3?$/ should work too.

danielweck commented 4 years ago

That being said, packaged EPUB loading works fine in the deployed cloud / web reader: https://readium.firebaseapp.com (0.32)

danielweck commented 4 years ago

Please use this release: https://github.com/readium/readium-js-viewer/releases/tag/0.32.0-alpha

danielweck commented 4 years ago

Code culprits: https://github.com/readium/readium-js-viewer/blob/57a5a47379acae01ad3c26ca8a31d22586f2a7be/src/js/ReadiumViewerLite.js#L78 https://github.com/readium/readium-js-viewer/blob/57a5a47379acae01ad3c26ca8a31d22586f2a7be/src/js/ReadiumViewer.js#L234 https://github.com/readium/readium-js-viewer/blob/4ab8dab28e7ae0a74f2b1716ea09d90f7cf399a4/src/js/EpubLibraryOPDS.js#L110 https://github.com/readium/readium-js/blob/999d7c32bcdd1184bcc248312267c6e744d737b9/js/epub-fetch/publication_fetcher.js#L91

...that said, the web/cloud reader seems to work fine in Firefox, so I am a bit puzzled.

danielweck commented 4 years ago

Ah, I now understand why everything seems to work fine: this is because the HTTP or drag-n-drop content-type is correctly informed application/epub+zip

danielweck commented 4 years ago

Reproducible error: https://readium.firebaseapp.com/?epub=http%3A%2F%2Freadium.firebaseapp.com%2Fepub_content%2Finternal_link.epub

curl -s -L -I -X GET "http://readium.firebaseapp.com/epub_content/internal_link.epub"

HTTP/1.1 301 Moved Permanently
Server: Varnish
Retry-After: 0
Location: https://readium.firebaseapp.com/epub_content/internal_link.epub
Content-Length: 0
Accept-Ranges: bytes
Date: Wed, 14 Oct 2020 09:03:42 GMT
Connection: close
X-Served-By: cache-lcy19280-LCY
X-Cache: HIT
X-Cache-Hits: 0
X-Timer: S1602666223.612537,VS0,VE0
HTTP/2 200 
access-control-allow-headers: Content-Type, Content-Length, Accept-Ranges, Content-Range, Range, Link, Transfer-Encoding
access-control-allow-methods: GET, HEAD, OPTIONS
access-control-allow-origin: *
access-control-expose-headers: Content-Type, Content-Length, Accept-Ranges, Content-Range, Range, Link, Transfer-Encoding
cache-control: max-age=3600
content-type: application/epub+zip
etag: "8c155fe64d8dbf7e9e274037f0d42bbe3cce105b575534dc4387e8e29869cb35"
last-modified: Tue, 19 Nov 2019 21:22:15 GMT
strict-transport-security: max-age=31556926; includeSubDomains; preload
accept-ranges: bytes
date: Wed, 14 Oct 2020 09:03:42 GMT
x-served-by: cache-lhr7335-LHR
x-cache: HIT
x-cache-hits: 1
x-timer: S1602666223.857484,VS0,VE1
vary: x-fh-requested-host, accept-encoding
content-length: 21577