Add filter:api.server.stats.get.result hook

pull/4624/head
Chocobozzz 2021-12-09 14:05:21 +01:00
parent a554bc1a26
commit 650580504c
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
5 changed files with 24 additions and 2 deletions

View File

@ -3,6 +3,7 @@ import { StatsManager } from '@server/lib/stat-manager'
import { ROUTE_CACHE_LIFETIME } from '../../../initializers/constants'
import { asyncMiddleware } from '../../../middlewares'
import { cacheRoute } from '../../../middlewares/cache/cache'
import { Hooks } from '@server/lib/plugins/hooks'
const statsRouter = express.Router()
@ -12,7 +13,8 @@ statsRouter.get('/stats',
)
async function getStats (_req: express.Request, res: express.Response) {
const data = await StatsManager.Instance.getStats()
let data = await StatsManager.Instance.getStats()
data = await Hooks.wrapObject(data, 'filter:api.server.stats.get.result')
return res.json(data)
}

View File

@ -233,6 +233,13 @@ async function register ({ registerHook, registerSetting, settingsManager, stora
}
})
registerHook({
target: 'filter:api.server.stats.get.result',
handler: (result) => {
return { ...result, customStats: 14 }
}
})
{
const filterHooks = [
'filter:api.search.videos.local.list.params',

View File

@ -125,7 +125,7 @@ describe('Test external auth plugins', function () {
expectedStatus: HttpStatusCode.BAD_REQUEST_400
})
await server.servers.waitUntilLog('expired external auth token', 2)
await server.servers.waitUntilLog('expired external auth token', 4)
})
it('Should auto login Cyan, create the user and use the token', async function () {

View File

@ -537,6 +537,16 @@ describe('Test plugin filter hooks', function () {
})
})
describe('Stats filters', function () {
it('Should run filter:api.server.stats.get.result', async function () {
const data = await servers[0].stats.get()
expect((data as any).customStats).to.equal(14)
})
})
after(async function () {
await cleanupTests(servers)
})

View File

@ -63,6 +63,9 @@ export const serverFilterHookObject = {
'filter:api.video-thread-comments.list.params': true,
'filter:api.video-thread-comments.list.result': true,
// Filter get stats result
'filter:api.server.stats.get.result': true,
// Filter result used to check if we need to auto blacklist a video
// (fired when a local or remote video is created or updated)
'filter:video.auto-blacklist.result': true,