mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-02-02 00:09:40 +00:00
Add:Purge items cache button and api endpoint
This commit is contained in:
parent
02d997897c
commit
142205f060
5 changed files with 56 additions and 7 deletions
|
|
@ -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 || ''
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue