]>
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' |
2a491182 | 10 | import { VideoChannelSyncLatestScheduler } from '@server/lib/schedulers/video-channel-sync-latest-scheduler' |
5d79474c C |
11 | |
12 | const debugRouter = express.Router() | |
13 | ||
14 | debugRouter.get('/debug', | |
15 | authenticate, | |
16 | ensureUserHasRight(UserRight.MANAGE_DEBUG), | |
a1587156 | 17 | getDebug |
5d79474c C |
18 | ) |
19 | ||
f6d6e7f8 | 20 | debugRouter.post('/debug/run-command', |
21 | authenticate, | |
22 | ensureUserHasRight(UserRight.MANAGE_DEBUG), | |
23 | runCommand | |
24 | ) | |
25 | ||
5d79474c C |
26 | // --------------------------------------------------------------------------- |
27 | ||
28 | export { | |
29 | debugRouter | |
30 | } | |
31 | ||
32 | // --------------------------------------------------------------------------- | |
33 | ||
a1587156 | 34 | function getDebug (req: express.Request, res: express.Response) { |
5d79474c | 35 | return res.json({ |
fae6e4da C |
36 | ip: req.ip, |
37 | activityPubMessagesWaiting: InboxManager.Instance.getActivityPubMessagesWaiting() | |
883a9019 | 38 | } as Debug) |
5d79474c | 39 | } |
f6d6e7f8 | 40 | |
41 | async function runCommand (req: express.Request, res: express.Response) { | |
42 | const body: SendDebugCommand = req.body | |
43 | ||
b2111066 C |
44 | const processors: { [id in SendDebugCommand['command']]: () => Promise<any> } = { |
45 | 'remove-dandling-resumable-uploads': () => RemoveDanglingResumableUploadsScheduler.Instance.execute(), | |
46 | 'process-video-views-buffer': () => VideoViewsBufferScheduler.Instance.execute(), | |
2a491182 F |
47 | 'process-video-viewers': () => VideoViewsManager.Instance.processViewerStats(), |
48 | 'process-video-channel-sync-latest': () => VideoChannelSyncLatestScheduler.Instance.execute() | |
f6d6e7f8 | 49 | } |
50 | ||
b2111066 C |
51 | await processors[body.command]() |
52 | ||
76148b27 | 53 | return res.status(HttpStatusCode.NO_CONTENT_204).end() |
f6d6e7f8 | 54 | } |