audiobookshelf/server/controllers/CacheController.js

43 lines
893 B
JavaScript
Raw Permalink Normal View History

2024-08-12 00:01:25 +02:00
const { Request, Response } = require('express')
2023-09-07 00:48:50 +02:00
const CacheManager = require('../managers/CacheManager')
2024-08-12 00:01:25 +02:00
/**
* @typedef RequestUserObject
* @property {import('../models/User')} user
*
* @typedef {Request & RequestUserObject} RequestWithUser
*/
class CacheController {
constructor() {}
2024-08-12 00:01:25 +02:00
/**
* POST: /api/cache/purge
*
* @param {RequestWithUser} req
* @param {Response} res
*/
async purgeCache(req, res) {
if (!req.user.isAdminOrUp) {
return res.sendStatus(403)
}
2023-09-07 00:48:50 +02:00
await CacheManager.purgeAll()
res.sendStatus(200)
}
2024-08-12 00:01:25 +02:00
/**
* POST: /api/cache/items/purge
*
* @param {RequestWithUser} req
* @param {Response} res
*/
async purgeItemsCache(req, res) {
if (!req.user.isAdminOrUp) {
return res.sendStatus(403)
}
2023-09-07 00:48:50 +02:00
await CacheManager.purgeItems()
res.sendStatus(200)
}
}
module.exports = new CacheController()