fix(reader): support dynamic token-fetcher for foliate PWA caching

Implement a custom callable fetcher function in the Foliate integration that
stringifies to the current auth token. This ensures backward compatibility
for older service-worker cached versions of the Foliate library expecting a
string token, while allowing newer/uncached versions to perform authenticated
requests correctly. Additionally, exclude Foliate assets from PWA precaching
to prevent stale cache bugs on Firefox.

Closes #575
This commit is contained in:
neon
2026-07-07 16:41:20 +00:00
parent 1405fdc13f
commit 0b11583f7d
5 changed files with 63 additions and 6 deletions
@@ -11,7 +11,16 @@
* @returns {Object} Loader interface compatible with Foliate's EPUB class
*/
export const makeStreamingLoader = (bookId, baseUrl, bookInfo, fetchFile = fetch, bookType = null, fileId = null) => {
const requestFile = typeof fetchFile === 'function' ? fetchFile : fetch
const requestFile =
typeof fetchFile === 'function'
? fetchFile
: typeof fetchFile === 'string' && fetchFile
? (input, init) => {
const headers = new Headers(init?.headers)
headers.set('Authorization', `Bearer ${fetchFile}`)
return fetch(input, { ...init, headers })
}
: fetch
const OPTIONAL_TEXT_FILES = new Set([
'META-INF/encryption.xml',
'META-INF/com.apple.ibooks.display-options.xml',