mirror of
https://github.com/bookorbit/bookorbit.git
synced 2026-11-03 00:11:37 -06:00
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:
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user