mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-07-21 19:34:43 +02:00
Update epub reader to use axios for handling refresh tokens
This commit is contained in:
parent
3c21c82ce1
commit
25fe4dee3a
1 changed files with 40 additions and 26 deletions
|
@ -97,9 +97,9 @@ export default {
|
||||||
},
|
},
|
||||||
ebookUrl() {
|
ebookUrl() {
|
||||||
if (this.fileId) {
|
if (this.fileId) {
|
||||||
return `${this.$config.routerBasePath}/api/items/${this.libraryItemId}/ebook/${this.fileId}`
|
return `/api/items/${this.libraryItemId}/ebook/${this.fileId}`
|
||||||
}
|
}
|
||||||
return `${this.$config.routerBasePath}/api/items/${this.libraryItemId}/ebook`
|
return `/api/items/${this.libraryItemId}/ebook`
|
||||||
},
|
},
|
||||||
themeRules() {
|
themeRules() {
|
||||||
const isDark = this.ereaderSettings.theme === 'dark'
|
const isDark = this.ereaderSettings.theme === 'dark'
|
||||||
|
@ -309,14 +309,24 @@ export default {
|
||||||
/** @type {EpubReader} */
|
/** @type {EpubReader} */
|
||||||
const reader = this
|
const reader = this
|
||||||
|
|
||||||
|
// Use axios to make request because we have token refresh logic in interceptor
|
||||||
|
const customRequest = async (url) => {
|
||||||
|
try {
|
||||||
|
return this.$axios.$get(url, {
|
||||||
|
responseType: 'arraybuffer'
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
console.error('EpubReader.initEpub customRequest failed:', error)
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** @type {ePub.Book} */
|
/** @type {ePub.Book} */
|
||||||
reader.book = new ePub(reader.ebookUrl, {
|
reader.book = new ePub(reader.ebookUrl, {
|
||||||
width: this.readerWidth,
|
width: this.readerWidth,
|
||||||
height: this.readerHeight - 50,
|
height: this.readerHeight - 50,
|
||||||
openAs: 'epub',
|
openAs: 'epub',
|
||||||
requestHeaders: {
|
requestMethod: customRequest
|
||||||
Authorization: `Bearer ${this.userToken}`
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
/** @type {ePub.Rendition} */
|
/** @type {ePub.Rendition} */
|
||||||
|
@ -337,29 +347,33 @@ export default {
|
||||||
this.applyTheme()
|
this.applyTheme()
|
||||||
})
|
})
|
||||||
|
|
||||||
reader.book.ready.then(() => {
|
reader.book.ready
|
||||||
// set up event listeners
|
.then(() => {
|
||||||
reader.rendition.on('relocated', reader.relocated)
|
// set up event listeners
|
||||||
reader.rendition.on('keydown', reader.keyUp)
|
reader.rendition.on('relocated', reader.relocated)
|
||||||
|
reader.rendition.on('keydown', reader.keyUp)
|
||||||
|
|
||||||
reader.rendition.on('touchstart', (event) => {
|
reader.rendition.on('touchstart', (event) => {
|
||||||
this.$emit('touchstart', event)
|
this.$emit('touchstart', event)
|
||||||
})
|
|
||||||
reader.rendition.on('touchend', (event) => {
|
|
||||||
this.$emit('touchend', event)
|
|
||||||
})
|
|
||||||
|
|
||||||
// load ebook cfi locations
|
|
||||||
const savedLocations = this.loadLocations()
|
|
||||||
if (savedLocations) {
|
|
||||||
reader.book.locations.load(savedLocations)
|
|
||||||
} else {
|
|
||||||
reader.book.locations.generate().then(() => {
|
|
||||||
this.checkSaveLocations(reader.book.locations.save())
|
|
||||||
})
|
})
|
||||||
}
|
reader.rendition.on('touchend', (event) => {
|
||||||
this.getChapters()
|
this.$emit('touchend', event)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// load ebook cfi locations
|
||||||
|
const savedLocations = this.loadLocations()
|
||||||
|
if (savedLocations) {
|
||||||
|
reader.book.locations.load(savedLocations)
|
||||||
|
} else {
|
||||||
|
reader.book.locations.generate().then(() => {
|
||||||
|
this.checkSaveLocations(reader.book.locations.save())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.getChapters()
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error('EpubReader.initEpub failed:', error)
|
||||||
|
})
|
||||||
},
|
},
|
||||||
getChapters() {
|
getChapters() {
|
||||||
// Load the list of chapters in the book. See https://github.com/futurepress/epub.js/issues/759
|
// Load the list of chapters in the book. See https://github.com/futurepress/epub.js/issues/759
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue