mirror of https://github.com/Chocobozzz/PeerTube
Add filter:api.server.stats.get.result hook
parent
a554bc1a26
commit
650580504c
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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 () {
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue