From 75aede914fb1fe56b8eef1e228183ca4218fec55 Mon Sep 17 00:00:00 2001 From: advplyr Date: Wed, 6 Oct 2021 13:00:12 -0500 Subject: [PATCH] Fix URL encoding, fix download m4b cover art --- client/components/modals/edit-tabs/Tracks.vue | 2 +- client/components/tables/TracksTable.vue | 2 +- client/layouts/default.vue | 1 + client/pages/audiobook/_id/index.vue | 1 + client/store/audiobooks.js | 17 +++++++++++------ server/DownloadManager.js | 4 ++-- server/Server.js | 6 ++---- 7 files changed, 19 insertions(+), 14 deletions(-) diff --git a/client/components/modals/edit-tabs/Tracks.vue b/client/components/modals/edit-tabs/Tracks.vue index b89d4164..5a254d38 100644 --- a/client/components/modals/edit-tabs/Tracks.vue +++ b/client/components/modals/edit-tabs/Tracks.vue @@ -69,7 +69,7 @@ export default { return { ...track, - relativePath: trackPath.replace(audiobookPath, '') + relativePath: trackPath.replace(audiobookPath, '').replace(/%/g, '%25').replace(/#/g, '%23') } }) }, diff --git a/client/components/tables/TracksTable.vue b/client/components/tables/TracksTable.vue index 700cdbcc..8f67c85f 100644 --- a/client/components/tables/TracksTable.vue +++ b/client/components/tables/TracksTable.vue @@ -75,7 +75,7 @@ export default { return { ...track, - relativePath: trackPath.replace(audiobookPath, '') + relativePath: trackPath.replace(audiobookPath, '').replace(/%/g, '%25').replace(/#/g, '%23') } }) }, diff --git a/client/layouts/default.vue b/client/layouts/default.vue index 042062d6..44097bcd 100644 --- a/client/layouts/default.vue +++ b/client/layouts/default.vue @@ -163,6 +163,7 @@ export default { if (!download || !download.audiobookId) { return console.error('Invalid download object', download) } + var audiobook = this.$store.getters['audiobooks/getAudiobook'](download.audiobookId) if (!audiobook) { return console.error('Audiobook not found for download', download) diff --git a/client/pages/audiobook/_id/index.vue b/client/pages/audiobook/_id/index.vue index 3b4ba951..a792e24f 100644 --- a/client/pages/audiobook/_id/index.vue +++ b/client/pages/audiobook/_id/index.vue @@ -113,6 +113,7 @@ export default { console.error('No audiobook...', params.id) return redirect('/') } + store.commit('audiobooks/addUpdate', audiobook) return { audiobook } diff --git a/client/store/audiobooks.js b/client/store/audiobooks.js index fc5729cf..4aaa2e61 100644 --- a/client/store/audiobooks.js +++ b/client/store/audiobooks.js @@ -1,6 +1,5 @@ import { sort } from '@/assets/fastSort' import { decode } from '@/plugins/init.client' -import Path from 'path' const STANDARD_GENRES = ['Adventure', 'Autobiography', 'Biography', 'Childrens', 'Comedy', 'Crime', 'Dystopian', 'Fantasy', 'Fiction', 'Health', 'History', 'Horror', 'Mystery', 'New Adult', 'Nonfiction', 'Philosophy', 'Politics', 'Religion', 'Romance', 'Sci-Fi', 'Self-Help', 'Short Story', 'Technology', 'Thriller', 'True Crime', 'Western', 'Young Adult'] @@ -138,15 +137,20 @@ export const getters = { var bookLastUpdate = book.lastUpdate || Date.now() var userToken = rootGetters['user/getToken'] + cover = cover.replace(/\\/g, '/') + // Map old covers to new format /s/book/{bookid}/* - if (cover.startsWith('\\local')) { - cover = cover.replace('local', `s\\book\\${bookItem.id}`) - if (cover.includes(bookItem.path + '\\')) { // Remove book path - cover = cover.replace(bookItem.path + '\\', '') + if (cover.startsWith('/local')) { + cover = cover.replace('local', `s/book/${bookItem.id}`) + if (cover.includes(bookItem.path + '/')) { // Remove book path + cover = cover.replace(bookItem.path + '/', '') } } - var url = new URL(cover, document.baseURI) + // Easier to replace these special characters then to encodeUriComponent of the filename + var encodedCover = cover.replace(/%/g, '%25').replace(/#/g, '%23') + + var url = new URL(encodedCover, document.baseURI) return url.href + `?token=${userToken}&ts=${bookLastUpdate}` } catch (err) { console.error(err) @@ -243,6 +247,7 @@ export const mutations = { }, addUpdate(state, audiobook) { if (audiobook.libraryId !== state.loadedLibraryId) { + console.warn('Invalid library', audiobook) return } diff --git a/server/DownloadManager.js b/server/DownloadManager.js index c2bd0326..8cea0428 100644 --- a/server/DownloadManager.js +++ b/server/DownloadManager.js @@ -240,8 +240,8 @@ class DownloadManager { } if (shouldIncludeCover) { - var _cover = audiobook.book.cover - if (_cover.startsWith(Path.sep + 'local')) { + var _cover = audiobook.book.coverFullPath + if (!_cover && audiobook.book.cover && audiobook.book.cover.startsWith(Path.sep + 'local')) { _cover = Path.join(this.AudiobookPath, _cover.replace(Path.sep + 'local', '')) Logger.debug('Local cover url', _cover) } diff --git a/server/Server.js b/server/Server.js index 6157e563..c83eb590 100644 --- a/server/Server.js +++ b/server/Server.js @@ -140,8 +140,7 @@ class Server { var folder = library.folders.find(fol => fol.id === req.params.folder) if (!folder) return res.status(404).send('Folder not found') - var remainingPath = decodeURIComponent(req.params['0']) - + var remainingPath = req.params['0'] var fullPath = Path.join(folder.fullPath, remainingPath) res.sendFile(fullPath) }) @@ -151,8 +150,7 @@ class Server { var audiobook = this.audiobooks.find(ab => ab.id === req.params.id) if (!audiobook) return res.status(404).send('Book not found with id ' + req.params.id) - var remainingPath = decodeURIComponent(req.params['0']) - + var remainingPath = req.params['0'] var fullPath = Path.join(audiobook.fullPath, remainingPath) res.sendFile(fullPath) })