mirror of
https://github.com/bookorbit/bookorbit.git
synced 2026-11-03 08:21:39 -06:00
feat: add audiobook progress and refactor metadata extraction
This commit is contained in:
@@ -7,9 +7,10 @@
|
||||
* @param {Object} bookInfo - Pre-fetched EPUB metadata from /info endpoint
|
||||
* @param {string} [authToken] - Optional authentication token
|
||||
* @param {string} [bookType] - Optional book type for alternative format (e.g., 'EPUB')
|
||||
* @param {number|null} [fileId] - Optional specific file ID to stream (for books with multiple epub files)
|
||||
* @returns {Object} Loader interface compatible with Foliate's EPUB class
|
||||
*/
|
||||
export const makeStreamingLoader = (bookId, baseUrl, bookInfo, authToken = null, bookType = null) => {
|
||||
export const makeStreamingLoader = (bookId, baseUrl, bookInfo, authToken = null, bookType = null, fileId = null) => {
|
||||
const OPTIONAL_TEXT_FILES = new Set([
|
||||
'META-INF/encryption.xml',
|
||||
'META-INF/com.apple.ibooks.display-options.xml',
|
||||
@@ -27,9 +28,11 @@ export const makeStreamingLoader = (bookId, baseUrl, bookInfo, authToken = null,
|
||||
// URL encode the path but preserve slashes
|
||||
const encodedPath = name.split('/').map(encodeURIComponent).join('/')
|
||||
let url = `${baseUrl}/${bookId}/file/${encodedPath}`
|
||||
if (bookType) {
|
||||
url += `?bookType=${encodeURIComponent(bookType)}`
|
||||
}
|
||||
const params = new URLSearchParams()
|
||||
if (bookType) params.append('bookType', bookType)
|
||||
if (fileId != null) params.append('fileId', String(fileId))
|
||||
const qs = params.toString()
|
||||
if (qs) url += `?${qs}`
|
||||
return url
|
||||
}
|
||||
|
||||
|
||||
@@ -158,10 +158,11 @@ export const makeBook = async (file) => {
|
||||
* @param {Object} bookInfo - Pre-fetched metadata from /api/v1/epub/{bookId}/info
|
||||
* @param {string} [authToken] - Optional authentication token
|
||||
* @param {string} [bookType] - Optional book type for alternative format (e.g., 'EPUB')
|
||||
* @param {number|null} [fileId] - Optional specific file ID (for books with multiple epub files)
|
||||
* @returns {Promise<EPUB>} Initialized EPUB book object
|
||||
*/
|
||||
export const makeStreamingBook = async (bookId, baseUrl, bookInfo, authToken = null, bookType = null) => {
|
||||
const loader = makeStreamingLoader(bookId, baseUrl, bookInfo, authToken, bookType)
|
||||
export const makeStreamingBook = async (bookId, baseUrl, bookInfo, authToken = null, bookType = null, fileId = null) => {
|
||||
const loader = makeStreamingLoader(bookId, baseUrl, bookInfo, authToken, bookType, fileId)
|
||||
const { EPUB } = await import('./epub.js')
|
||||
return new EPUB(loader).init()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user