]>
Commit | Line | Data |
---|---|---|
41fb13c3 | 1 | import express from 'express' |
fae6e4da | 2 | import { InboxManager } from '@server/lib/activitypub/inbox-manager' |
f6d6e7f8 | 3 | import { RemoveDanglingResumableUploadsScheduler } from '@server/lib/schedulers/remove-dangling-resumable-uploads-scheduler' |
b2111066 C |
4 | import { VideoViewsBufferScheduler } from '@server/lib/schedulers/video-views-buffer-scheduler' |
5 | import { VideoViewsManager } from '@server/lib/views/video-views-manager' | |
883a9019 | 6 | import { Debug, SendDebugCommand } from '@shared/models' |
c0e8b12e | 7 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' |
5d79474c | 8 | import { UserRight } from '../../../../shared/models/users' |
a1587156 | 9 | import { authenticate, ensureUserHasRight } from '../../../middlewares' |
5d79474c C |
10 | |
11 | const debugRouter = express.Router() | |
12 | ||
13 | debugRouter.get('/debug', | |
14 | authenticate, | |
15 | ensureUserHasRight(UserRight.MANAGE_DEBUG), | |
a1587156 | 16 | getDebug |
5d79474c C |
17 | ) |
18 | ||
f6d6e7f8 | 19 | debugRouter.post('/debug/run-command', |
20 | authenticate, | |
21 | ensureUserHasRight(UserRight.MANAGE_DEBUG), | |
22 | runCommand | |
23 | ) | |
24 | ||
5d79474c C |
25 | // --------------------------------------------------------------------------- |
26 | ||
27 | export { | |
28 | debugRouter | |
29 | } | |
30 | ||
31 | // --------------------------------------------------------------------------- | |
32 | ||
a1587156 | 33 | function 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 | |
40 | async 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 | } |