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')
|
2022-11-19 20:28:06 +01:00
|
|
|
|
2024-08-12 00:01:25 +02:00
|
|
|
/**
|
|
|
|
* @typedef RequestUserObject
|
|
|
|
* @property {import('../models/User')} user
|
|
|
|
*
|
|
|
|
* @typedef {Request & RequestUserObject} RequestWithUser
|
|
|
|
*/
|
|
|
|
|
2022-11-19 20:28:06 +01:00
|
|
|
class CacheController {
|
2024-08-11 00:15:21 +02:00
|
|
|
constructor() {}
|
2022-11-19 20:28:06 +01:00
|
|
|
|
2024-08-12 00:01:25 +02:00
|
|
|
/**
|
|
|
|
* POST: /api/cache/purge
|
|
|
|
*
|
|
|
|
* @param {RequestWithUser} req
|
|
|
|
* @param {Response} res
|
|
|
|
*/
|
2022-11-19 20:28:06 +01:00
|
|
|
async purgeCache(req, res) {
|
2024-08-11 23:07:29 +02:00
|
|
|
if (!req.user.isAdminOrUp) {
|
2022-11-19 20:28:06 +01:00
|
|
|
return res.sendStatus(403)
|
|
|
|
}
|
2023-09-07 00:48:50 +02:00
|
|
|
await CacheManager.purgeAll()
|
2022-11-19 20:28:06 +01:00
|
|
|
res.sendStatus(200)
|
|
|
|
}
|
|
|
|
|
2024-08-12 00:01:25 +02:00
|
|
|
/**
|
|
|
|
* POST: /api/cache/items/purge
|
|
|
|
*
|
|
|
|
* @param {RequestWithUser} req
|
|
|
|
* @param {Response} res
|
|
|
|
*/
|
2022-11-19 20:28:06 +01:00
|
|
|
async purgeItemsCache(req, res) {
|
2024-08-11 23:07:29 +02:00
|
|
|
if (!req.user.isAdminOrUp) {
|
2022-11-19 20:28:06 +01:00
|
|
|
return res.sendStatus(403)
|
|
|
|
}
|
2023-09-07 00:48:50 +02:00
|
|
|
await CacheManager.purgeItems()
|
2022-11-19 20:28:06 +01:00
|
|
|
res.sendStatus(200)
|
|
|
|
}
|
|
|
|
}
|
2024-08-11 00:15:21 +02:00
|
|
|
module.exports = new CacheController()
|