diff --git a/android/app/src/main/java/com/audiobookshelf/app/models/DownloadItemPart.kt b/android/app/src/main/java/com/audiobookshelf/app/models/DownloadItemPart.kt index d2fa1be1..f5a71b6c 100644 --- a/android/app/src/main/java/com/audiobookshelf/app/models/DownloadItemPart.kt +++ b/android/app/src/main/java/com/audiobookshelf/app/models/DownloadItemPart.kt @@ -41,8 +41,11 @@ data class DownloadItemPart( val destinationUri = Uri.fromFile(destinationFile) val finalDestinationUri = Uri.fromFile(finalDestinationFile) - var downloadUrl = "${DeviceManager.serverAddress}${serverPath}?token=${DeviceManager.token}" - if (serverPath.endsWith("/cover")) downloadUrl += "&format=jpeg&raw=1" // For cover images force to jpeg + var downloadUrl = "${DeviceManager.serverAddress}${serverPath}" + + downloadUrl += if (serverPath.endsWith("/cover")) "?raw=1" // Download raw cover image + else "?token=${DeviceManager.token}" + val downloadUri = Uri.parse(downloadUrl) Log.d("DownloadItemPart", "Audio File Destination Uri: $destinationUri | Final Destination Uri: $finalDestinationUri | Download URI $downloadUri") return DownloadItemPart( @@ -77,7 +80,7 @@ data class DownloadItemPart( val isInternalStorage get() = localFolderId.startsWith("internal-") @get:JsonIgnore - val serverUrl get() = "${DeviceManager.serverAddress}${serverPath}?token=${DeviceManager.token}" + val serverUrl get() = uri.toString() @JsonIgnore fun getDownloadRequest(): DownloadManager.Request { diff --git a/components/cards/AuthorCard.vue b/components/cards/AuthorCard.vue index ad6fcf69..fbc2365f 100644 --- a/components/cards/AuthorCard.vue +++ b/components/cards/AuthorCard.vue @@ -42,9 +42,6 @@ export default { } }, computed: { - userToken() { - return this.$store.getters['user/getToken'] - }, _author() { return this.author || {} }, diff --git a/components/covers/AuthorImage.vue b/components/covers/AuthorImage.vue index 2296fbba..0d1fea6e 100644 --- a/components/covers/AuthorImage.vue +++ b/components/covers/AuthorImage.vue @@ -39,9 +39,6 @@ export default { } }, computed: { - userToken() { - return this.$store.getters['user/getToken'] - }, _author() { return this.author || {} }, @@ -61,9 +58,9 @@ export default { if (!this.imagePath || !this.serverAddress) return null if (process.env.NODE_ENV !== 'production' && this.serverAddress.startsWith('http://192.168')) { // Testing - return `http://localhost:3333/api/authors/${this.authorId}/image?token=${this.userToken}&ts=${this.updatedAt}` + return `http://localhost:3333/api/authors/${this.authorId}/image?ts=${this.updatedAt}` } - return `${this.serverAddress}/api/authors/${this.authorId}/image?token=${this.userToken}&ts=${this.updatedAt}` + return `${this.serverAddress}/api/authors/${this.authorId}/image?ts=${this.updatedAt}` } }, methods: { diff --git a/components/covers/BookCover.vue b/components/covers/BookCover.vue index 8f97a65b..9efeaa41 100644 --- a/components/covers/BookCover.vue +++ b/components/covers/BookCover.vue @@ -141,9 +141,6 @@ export default { }, authorBottom() { return 0.75 * this.sizeMultiplier - }, - userToken() { - return this.$store.getters['user/getToken'] } }, methods: { diff --git a/components/tables/ebook/EbookFilesTable.vue b/components/tables/ebook/EbookFilesTable.vue index 1542b654..ab51fc0d 100644 --- a/components/tables/ebook/EbookFilesTable.vue +++ b/components/tables/ebook/EbookFilesTable.vue @@ -50,9 +50,6 @@ export default { libraryItemId() { return this.libraryItem.id }, - userToken() { - return this.$store.getters['user/getToken'] - }, ebookFiles() { return (this.libraryItem.libraryFiles || []).filter((lf) => lf.fileType === 'ebook') }, diff --git a/components/tables/ebook/EbookFilesTableRow.vue b/components/tables/ebook/EbookFilesTableRow.vue index 999cfd80..0c81a90c 100644 --- a/components/tables/ebook/EbookFilesTableRow.vue +++ b/components/tables/ebook/EbookFilesTableRow.vue @@ -24,9 +24,6 @@ export default { return {} }, computed: { - userToken() { - return this.$store.getters['user/getToken'] - }, userCanUpdate() { return this.$store.getters['user/getUserCanUpdate'] }, diff --git a/pages/item/_id/index.vue b/pages/item/_id/index.vue index 00012699..41421e2a 100644 --- a/pages/item/_id/index.vue +++ b/pages/item/_id/index.vue @@ -366,9 +366,6 @@ export default { user() { return this.$store.state.user.user }, - userToken() { - return this.$store.getters['user/getToken'] - }, userItemProgress() { if (this.isPodcast) return null if (this.isLocal) return this.localItemProgress diff --git a/store/globals.js b/store/globals.js index 7ecfc85f..e4fbb37a 100644 --- a/store/globals.js +++ b/store/globals.js @@ -44,62 +44,71 @@ export const state = () => ({ }) export const getters = { - getDownloadItem: state => (libraryItemId, episodeId = null) => { - return state.itemDownloads.find(i => { - // if (episodeId && !i.episodes.some(e => e.id == episodeId)) return false - if (episodeId && i.episodeId !== episodeId) return false - return i.libraryItemId == libraryItemId - }) - }, - getLibraryItemCoverSrc: (state, getters, rootState, rootGetters) => (libraryItem, placeholder, raw = false) => { - if (!libraryItem) return placeholder - const media = libraryItem.media - if (!media || !media.coverPath || media.coverPath === placeholder) return placeholder + getDownloadItem: + (state) => + (libraryItemId, episodeId = null) => { + return state.itemDownloads.find((i) => { + // if (episodeId && !i.episodes.some(e => e.id == episodeId)) return false + if (episodeId && i.episodeId !== episodeId) return false + return i.libraryItemId == libraryItemId + }) + }, + getLibraryItemCoverSrc: + (state, getters, rootState, rootGetters) => + (libraryItem, placeholder, raw = false) => { + if (!libraryItem) return placeholder + const media = libraryItem.media + if (!media || !media.coverPath || media.coverPath === placeholder) return placeholder - // Absolute URL covers (should no longer be used) - if (media.coverPath.startsWith('http:') || media.coverPath.startsWith('https:')) return media.coverPath + // Absolute URL covers (should no longer be used) + if (media.coverPath.startsWith('http:') || media.coverPath.startsWith('https:')) return media.coverPath - const userToken = rootGetters['user/getToken'] - const serverAddress = rootGetters['user/getServerAddress'] - if (!userToken || !serverAddress) return placeholder + const serverAddress = rootGetters['user/getServerAddress'] + if (!serverAddress) return placeholder - const lastUpdate = libraryItem.updatedAt || Date.now() + const lastUpdate = libraryItem.updatedAt || Date.now() - if (process.env.NODE_ENV !== 'production') { // Testing - // return `http://localhost:3333/api/items/${libraryItem.id}/cover?token=${userToken}&ts=${lastUpdate}` - } + if (process.env.NODE_ENV !== 'production') { + // Testing + // return `http://localhost:3333/api/items/${libraryItem.id}/cover?ts=${lastUpdate}` + } - const url = new URL(`${serverAddress}/api/items/${libraryItem.id}/cover`) - return `${url}?token=${userToken}&ts=${lastUpdate}${raw ? '&raw=1' : ''}` - }, - getLibraryItemCoverSrcById: (state, getters, rootState, rootGetters) => (libraryItemId, placeholder = null) => { - if (!placeholder) placeholder = `${rootState.routerBasePath}/book_placeholder.jpg` - if (!libraryItemId) return placeholder - const userToken = rootGetters['user/getToken'] - const serverAddress = rootGetters['user/getServerAddress'] - if (!userToken || !serverAddress) return placeholder + const url = new URL(`${serverAddress}/api/items/${libraryItem.id}/cover`) + return `${url}?ts=${lastUpdate}${raw ? '&raw=1' : ''}` + }, + getLibraryItemCoverSrcById: + (state, getters, rootState, rootGetters) => + (libraryItemId, placeholder = null) => { + if (!placeholder) placeholder = `${rootState.routerBasePath}/book_placeholder.jpg` + if (!libraryItemId) return placeholder + const serverAddress = rootGetters['user/getServerAddress'] + if (!serverAddress) return placeholder - const url = new URL(`${serverAddress}/api/items/${libraryItemId}/cover`) - return `${url}?token=${userToken}` - }, - getLocalMediaProgressById: (state) => (localLibraryItemId, episodeId = null) => { - return state.localMediaProgress.find(lmp => { - if (episodeId != null && lmp.localEpisodeId != episodeId) return false - return lmp.localLibraryItemId == localLibraryItemId - }) - }, - getLocalMediaProgressByServerItemId: (state) => (libraryItemId, episodeId = null) => { - return state.localMediaProgress.find(lmp => { - if (episodeId != null && lmp.episodeId != episodeId) return false - return lmp.libraryItemId == libraryItemId - }) - }, - getJumpForwardIcon: state => (jumpForwardTime) => { - const item = state.jumpForwardItems.find(i => i.value == jumpForwardTime) + const url = new URL(`${serverAddress}/api/items/${libraryItemId}/cover`) + return url.toString() + }, + getLocalMediaProgressById: + (state) => + (localLibraryItemId, episodeId = null) => { + return state.localMediaProgress.find((lmp) => { + if (episodeId != null && lmp.localEpisodeId != episodeId) return false + return lmp.localLibraryItemId == localLibraryItemId + }) + }, + getLocalMediaProgressByServerItemId: + (state) => + (libraryItemId, episodeId = null) => { + return state.localMediaProgress.find((lmp) => { + if (episodeId != null && lmp.episodeId != episodeId) return false + return lmp.libraryItemId == libraryItemId + }) + }, + getJumpForwardIcon: (state) => (jumpForwardTime) => { + const item = state.jumpForwardItems.find((i) => i.value == jumpForwardTime) return item ? item.icon : 'forward_10' }, - getJumpBackwardsIcon: state => (jumpBackwardsTime) => { - const item = state.jumpBackwardsItems.find(i => i.value == jumpBackwardsTime) + getJumpBackwardsIcon: (state) => (jumpBackwardsTime) => { + const item = state.jumpBackwardsItems.find((i) => i.value == jumpBackwardsTime) return item ? item.icon : 'replay_10' } } @@ -116,7 +125,7 @@ export const mutations = { state.isModalOpen = val }, addUpdateItemDownload(state, downloadItem) { - var index = state.itemDownloads.findIndex(i => i.id == downloadItem.id) + var index = state.itemDownloads.findIndex((i) => i.id == downloadItem.id) if (index >= 0) { state.itemDownloads.splice(index, 1, downloadItem) } else { @@ -124,7 +133,7 @@ export const mutations = { } }, updateDownloadItemPart(state, downloadItemPart) { - const downloadItem = state.itemDownloads.find(i => i.id == downloadItemPart.downloadItemId) + const downloadItem = state.itemDownloads.find((i) => i.id == downloadItemPart.downloadItemId) if (!downloadItem) { console.error('updateDownloadItemPart: Download item not found for itemPart', JSON.stringify(downloadItemPart)) return @@ -132,7 +141,7 @@ export const mutations = { let totalBytes = 0 let totalBytesDownloaded = 0 - downloadItem.downloadItemParts = downloadItem.downloadItemParts.map(dip => { + downloadItem.downloadItemParts = downloadItem.downloadItemParts.map((dip) => { let newDip = dip.id == downloadItemPart.id ? downloadItemPart : dip totalBytes += newDip.completed ? Number(newDip.bytesDownloaded) : Number(newDip.fileSize) @@ -149,7 +158,7 @@ export const mutations = { } }, removeItemDownload(state, id) { - state.itemDownloads = state.itemDownloads.filter(i => i.id != id) + state.itemDownloads = state.itemDownloads.filter((i) => i.id != id) }, setBookshelfListView(state, val) { state.bookshelfListView = val @@ -164,7 +173,7 @@ export const mutations = { if (!prog || !prog.id) { return } - var index = state.localMediaProgress.findIndex(lmp => lmp.id == prog.id) + var index = state.localMediaProgress.findIndex((lmp) => lmp.id == prog.id) if (index >= 0) { state.localMediaProgress.splice(index, 1, prog) } else { @@ -172,10 +181,10 @@ export const mutations = { } }, removeLocalMediaProgress(state, id) { - state.localMediaProgress = state.localMediaProgress.filter(lmp => lmp.id != id) + state.localMediaProgress = state.localMediaProgress.filter((lmp) => lmp.id != id) }, removeLocalMediaProgressForItem(state, llid) { - state.localMediaProgress = state.localMediaProgress.filter(lmp => lmp.localLibraryItemId !== llid) + state.localMediaProgress = state.localMediaProgress.filter((lmp) => lmp.localLibraryItemId !== llid) }, setLastSearch(state, val) { state.lastSearch = val @@ -203,4 +212,4 @@ export const mutations = { state.rssFeedEntity = entity state.showRSSFeedOpenCloseModal = true } -} \ No newline at end of file +}