mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2024-11-07 16:44:16 +01:00
43 lines
893 B
JavaScript
43 lines
893 B
JavaScript
const { Request, Response } = require('express')
|
|
const CacheManager = require('../managers/CacheManager')
|
|
|
|
/**
|
|
* @typedef RequestUserObject
|
|
* @property {import('../models/User')} user
|
|
*
|
|
* @typedef {Request & RequestUserObject} RequestWithUser
|
|
*/
|
|
|
|
class CacheController {
|
|
constructor() {}
|
|
|
|
/**
|
|
* POST: /api/cache/purge
|
|
*
|
|
* @param {RequestWithUser} req
|
|
* @param {Response} res
|
|
*/
|
|
async purgeCache(req, res) {
|
|
if (!req.user.isAdminOrUp) {
|
|
return res.sendStatus(403)
|
|
}
|
|
await CacheManager.purgeAll()
|
|
res.sendStatus(200)
|
|
}
|
|
|
|
/**
|
|
* POST: /api/cache/items/purge
|
|
*
|
|
* @param {RequestWithUser} req
|
|
* @param {Response} res
|
|
*/
|
|
async purgeItemsCache(req, res) {
|
|
if (!req.user.isAdminOrUp) {
|
|
return res.sendStatus(403)
|
|
}
|
|
await CacheManager.purgeItems()
|
|
res.sendStatus(200)
|
|
}
|
|
}
|
|
module.exports = new CacheController()
|