]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/controllers/api/server/debug.ts
Merge branch 'release/4.2.0' into develop
[github/Chocobozzz/PeerTube.git] / server / controllers / api / server / debug.ts
CommitLineData
41fb13c3 1import express from 'express'
fae6e4da 2import { InboxManager } from '@server/lib/activitypub/inbox-manager'
f6d6e7f8 3import { RemoveDanglingResumableUploadsScheduler } from '@server/lib/schedulers/remove-dangling-resumable-uploads-scheduler'
b2111066
C
4import { VideoViewsBufferScheduler } from '@server/lib/schedulers/video-views-buffer-scheduler'
5import { VideoViewsManager } from '@server/lib/views/video-views-manager'
883a9019 6import { Debug, SendDebugCommand } from '@shared/models'
c0e8b12e 7import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes'
5d79474c 8import { UserRight } from '../../../../shared/models/users'
a1587156 9import { authenticate, ensureUserHasRight } from '../../../middlewares'
5d79474c
C
10
11const debugRouter = express.Router()
12
13debugRouter.get('/debug',
14 authenticate,
15 ensureUserHasRight(UserRight.MANAGE_DEBUG),
a1587156 16 getDebug
5d79474c
C
17)
18
f6d6e7f8 19debugRouter.post('/debug/run-command',
20 authenticate,
21 ensureUserHasRight(UserRight.MANAGE_DEBUG),
22 runCommand
23)
24
5d79474c
C
25// ---------------------------------------------------------------------------
26
27export {
28 debugRouter
29}
30
31// ---------------------------------------------------------------------------
32
a1587156 33function getDebug (req: express.Request, res: express.Response) {
5d79474c 34 return res.json({
fae6e4da
C
35 ip: req.ip,
36 activityPubMessagesWaiting: InboxManager.Instance.getActivityPubMessagesWaiting()
883a9019 37 } as Debug)
5d79474c 38}
f6d6e7f8 39
40async function runCommand (req: express.Request, res: express.Response) {
41 const body: SendDebugCommand = req.body
42
b2111066
C
43 const processors: { [id in SendDebugCommand['command']]: () => Promise<any> } = {
44 'remove-dandling-resumable-uploads': () => RemoveDanglingResumableUploadsScheduler.Instance.execute(),
45 'process-video-views-buffer': () => VideoViewsBufferScheduler.Instance.execute(),
ac907dc7 46 'process-video-viewers': () => VideoViewsManager.Instance.processViewerStats()
f6d6e7f8 47 }
48
b2111066
C
49 await processors[body.command]()
50
76148b27 51 return res.status(HttpStatusCode.NO_CONTENT_204).end()
f6d6e7f8 52}