1
0
Fork 0

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

This commit is contained in:
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,