diff --git a/client/components/prompt/Confirm.vue b/client/components/prompt/Confirm.vue index 700cf168..a2b61339 100644 --- a/client/components/prompt/Confirm.vue +++ b/client/components/prompt/Confirm.vue @@ -3,7 +3,7 @@
{{ message }}
+
Report bugs, request features, and contribute on
@@ -421,7 +425,7 @@ export default {
this.showConfirmPurgeCache = false
this.isPurgingCache = true
await this.$axios
- .$post('/api/purgecache')
+ .$post('/api/cache/purge')
.then(() => {
this.$toast.success('Cache Purged!')
})
@@ -430,6 +434,31 @@ export default {
this.$toast.error('Failed to purge cache')
})
this.isPurgingCache = false
+ },
+ purgeItemsCache() {
+ const payload = {
+ message: `Warning! This will delete the entire folder at /metadata/cache/items.
Are you sure you want to purge items cache?`,
+ callback: (confirmed) => {
+ if (confirmed) {
+ this.sendPurgeItemsCache()
+ }
+ },
+ type: 'yesNo'
+ }
+ this.$store.commit('globals/setConfirmPrompt', payload)
+ },
+ async sendPurgeItemsCache() {
+ this.isPurgingCache = true
+ await this.$axios
+ .$post('/api/cache/items/purge')
+ .then(() => {
+ this.$toast.success('Items Cache Purged!')
+ })
+ .catch((error) => {
+ console.error('Failed to purge items cache', error)
+ this.$toast.error('Failed to purge items cache')
+ })
+ this.isPurgingCache = false
}
},
mounted() {
diff --git a/server/controllers/MiscController.js b/server/controllers/MiscController.js
index 8cba1acc..2a3029cc 100644
--- a/server/controllers/MiscController.js
+++ b/server/controllers/MiscController.js
@@ -158,16 +158,26 @@ class MiscController {
})
}
- // POST: api/purgecache (admin)
+ // POST: api/cache/purge (admin)
async purgeCache(req, res) {
if (!req.user.isAdminOrUp) {
return res.sendStatus(403)
}
- Logger.info(`[ApiRouter] Purging all cache`)
+ Logger.info(`[MiscController] Purging all cache`)
await this.cacheManager.purgeAll()
res.sendStatus(200)
}
+ // POST: api/cache/items/purge
+ async purgeItemsCache(req, res) {
+ if (!req.user.isAdminOrUp) {
+ return res.sendStatus(403)
+ }
+ Logger.info(`[MiscController] Purging items cache`)
+ await this.cacheManager.purgeItems()
+ res.sendStatus(200)
+ }
+
async findBooks(req, res) {
var provider = req.query.provider || 'google'
var title = req.query.title || ''
diff --git a/server/managers/CacheManager.js b/server/managers/CacheManager.js
index dccd8faa..78543ac9 100644
--- a/server/managers/CacheManager.js
+++ b/server/managers/CacheManager.js
@@ -114,6 +114,15 @@ class CacheManager {
await this.ensureCachePaths()
}
+ async purgeItems() {
+ if (await fs.pathExists(this.ItemCachePath)) {
+ await fs.remove(this.ItemCachePath).catch((error) => {
+ Logger.error(`[CacheManager] Failed to remove items cache dir "${this.ItemCachePath}"`, error)
+ })
+ }
+ await this.ensureCachePaths()
+ }
+
async handleAuthorCache(res, author, options = {}) {
const format = options.format || 'webp'
const width = options.width || 400
diff --git a/server/routers/ApiRouter.js b/server/routers/ApiRouter.js
index d5b46feb..e45adc4c 100644
--- a/server/routers/ApiRouter.js
+++ b/server/routers/ApiRouter.js
@@ -227,8 +227,9 @@ class ApiRouter {
this.router.get('/encode-m4b/:id', MiscController.encodeM4b.bind(this))
this.router.post('/encode-m4b/:id/cancel', MiscController.cancelM4bEncode.bind(this))
this.router.get('/tasks', MiscController.getTasks.bind(this))
- this.router.patch('/settings', MiscController.updateServerSettings.bind(this)) // Root only
- this.router.post('/purgecache', MiscController.purgeCache.bind(this)) // Root only
+ this.router.patch('/settings', MiscController.updateServerSettings.bind(this))
+ this.router.post('/cache/purge', MiscController.purgeCache.bind(this))
+ this.router.post('/cache/items/purge', MiscController.purgeItemsCache.bind(this))
this.router.post('/authorize', MiscController.authorize.bind(this))
this.router.get('/search/covers', MiscController.findCovers.bind(this))
this.router.get('/search/books', MiscController.findBooks.bind(this))