From b957e1a36ba45f93c227b8f4e797034142fd6b36 Mon Sep 17 00:00:00 2001 From: advplyr Date: Fri, 3 Feb 2023 17:50:42 -0600 Subject: [PATCH] Update:API endpoints for library and library item scan updated to POST requests --- client/components/cards/LazyBookCard.vue | 2 +- client/components/modals/item/tabs/Details.vue | 2 +- client/store/libraries.js | 2 +- server/controllers/LibraryController.js | 4 ++-- server/controllers/LibraryItemController.js | 4 ++-- server/routers/ApiRouter.js | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/client/components/cards/LazyBookCard.vue b/client/components/cards/LazyBookCard.vue index 171b72cd..4ecec4f1 100644 --- a/client/components/cards/LazyBookCard.vue +++ b/client/components/cards/LazyBookCard.vue @@ -662,7 +662,7 @@ export default { const axios = this.$axios || this.$nuxt.$axios this.processing = true axios - .$get(`/api/items/${this.libraryItemId}/scan`) + .$post(`/api/items/${this.libraryItemId}/scan`) .then((data) => { var result = data.result if (!result) { diff --git a/client/components/modals/item/tabs/Details.vue b/client/components/modals/item/tabs/Details.vue index 11f6abfb..e95b8d57 100644 --- a/client/components/modals/item/tabs/Details.vue +++ b/client/components/modals/item/tabs/Details.vue @@ -129,7 +129,7 @@ export default { rescan() { this.rescanning = true this.$axios - .$get(`/api/items/${this.libraryItemId}/scan`) + .$post(`/api/items/${this.libraryItemId}/scan`) .then((data) => { this.rescanning = false var result = data.result diff --git a/client/store/libraries.js b/client/store/libraries.js index 15a9fa36..e9385483 100644 --- a/client/store/libraries.js +++ b/client/store/libraries.js @@ -66,7 +66,7 @@ export const getters = { export const actions = { requestLibraryScan({ state, commit }, { libraryId, force }) { - return this.$axios.$get(`/api/libraries/${libraryId}/scan`, { params: { force } }) + return this.$axios.$post(`/api/libraries/${libraryId}/scan?force=${force ? 1 : 0}`) }, loadFolders({ state, commit }) { if (state.folders.length) { diff --git a/server/controllers/LibraryController.js b/server/controllers/LibraryController.js index 87d28007..d09d52d4 100644 --- a/server/controllers/LibraryController.js +++ b/server/controllers/LibraryController.js @@ -684,13 +684,13 @@ class LibraryController { res.sendStatus(200) } - // GET: api/libraries/:id/scan + // POST: api/libraries/:id/scan async scan(req, res) { if (!req.user.isAdminOrUp) { Logger.error(`[LibraryController] Non-root user attempted to scan library`, req.user) return res.sendStatus(403) } - var options = { + const options = { forceRescan: req.query.force == 1 } res.sendStatus(200) diff --git a/server/controllers/LibraryItemController.js b/server/controllers/LibraryItemController.js index f630c2dc..553095d6 100644 --- a/server/controllers/LibraryItemController.js +++ b/server/controllers/LibraryItemController.js @@ -203,7 +203,7 @@ class LibraryItemController { if (global.XAccel) { Logger.debug(`Use X-Accel to serve static file ${libraryItem.media.coverPath}`) - return res.status(204).header({'X-Accel-Redirect': global.XAccel + libraryItem.media.coverPath}).send() + return res.status(204).header({ 'X-Accel-Redirect': global.XAccel + libraryItem.media.coverPath }).send() } return res.sendFile(libraryItem.media.coverPath) } @@ -389,7 +389,7 @@ class LibraryItemController { else res.sendStatus(500) } - // GET: api/items/:id/scan (admin) + // POST: api/items/:id/scan (admin) async scan(req, res) { if (!req.user.isAdminOrUp) { Logger.error(`[LibraryItemController] Non-admin user attempted to scan library item`, req.user) diff --git a/server/routers/ApiRouter.js b/server/routers/ApiRouter.js index 370b2c00..42a91214 100644 --- a/server/routers/ApiRouter.js +++ b/server/routers/ApiRouter.js @@ -86,7 +86,7 @@ class ApiRouter { this.router.get('/libraries/:id/stats', LibraryController.middleware.bind(this), LibraryController.stats.bind(this)) this.router.get('/libraries/:id/authors', LibraryController.middleware.bind(this), LibraryController.getAuthors.bind(this)) this.router.get('/libraries/:id/matchall', LibraryController.middleware.bind(this), LibraryController.matchAll.bind(this)) - this.router.get('/libraries/:id/scan', LibraryController.middleware.bind(this), LibraryController.scan.bind(this)) + this.router.post('/libraries/:id/scan', LibraryController.middleware.bind(this), LibraryController.scan.bind(this)) this.router.get('/libraries/:id/recent-episodes', LibraryController.middleware.bind(this), LibraryController.getRecentEpisodes.bind(this)) this.router.post('/libraries/order', LibraryController.reorder.bind(this)) @@ -108,7 +108,7 @@ class ApiRouter { this.router.post('/items/:id/play', LibraryItemController.middleware.bind(this), LibraryItemController.startPlaybackSession.bind(this)) this.router.post('/items/:id/play/:episodeId', LibraryItemController.middleware.bind(this), LibraryItemController.startEpisodePlaybackSession.bind(this)) this.router.patch('/items/:id/tracks', LibraryItemController.middleware.bind(this), LibraryItemController.updateTracks.bind(this)) - this.router.get('/items/:id/scan', LibraryItemController.middleware.bind(this), LibraryItemController.scan.bind(this)) + this.router.post('/items/:id/scan', LibraryItemController.middleware.bind(this), LibraryItemController.scan.bind(this)) this.router.get('/items/:id/tone-object', LibraryItemController.middleware.bind(this), LibraryItemController.getToneMetadataObject.bind(this)) this.router.post('/items/:id/chapters', LibraryItemController.middleware.bind(this), LibraryItemController.updateMediaChapters.bind(this)) this.router.post('/items/:id/tone-scan/:index?', LibraryItemController.middleware.bind(this), LibraryItemController.toneScan.bind(this))