]>
Commit | Line | Data |
---|---|---|
1 | import express from 'express' | |
2 | import { InboxManager } from '@server/lib/activitypub/inbox-manager' | |
3 | import { RemoveDanglingResumableUploadsScheduler } from '@server/lib/schedulers/remove-dangling-resumable-uploads-scheduler' | |
4 | import { Debug, SendDebugCommand } from '@shared/models' | |
5 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' | |
6 | import { UserRight } from '../../../../shared/models/users' | |
7 | import { authenticate, ensureUserHasRight } from '../../../middlewares' | |
8 | ||
9 | const debugRouter = express.Router() | |
10 | ||
11 | debugRouter.get('/debug', | |
12 | authenticate, | |
13 | ensureUserHasRight(UserRight.MANAGE_DEBUG), | |
14 | getDebug | |
15 | ) | |
16 | ||
17 | debugRouter.post('/debug/run-command', | |
18 | authenticate, | |
19 | ensureUserHasRight(UserRight.MANAGE_DEBUG), | |
20 | runCommand | |
21 | ) | |
22 | ||
23 | // --------------------------------------------------------------------------- | |
24 | ||
25 | export { | |
26 | debugRouter | |
27 | } | |
28 | ||
29 | // --------------------------------------------------------------------------- | |
30 | ||
31 | function getDebug (req: express.Request, res: express.Response) { | |
32 | return res.json({ | |
33 | ip: req.ip, | |
34 | activityPubMessagesWaiting: InboxManager.Instance.getActivityPubMessagesWaiting() | |
35 | } as Debug) | |
36 | } | |
37 | ||
38 | async function runCommand (req: express.Request, res: express.Response) { | |
39 | const body: SendDebugCommand = req.body | |
40 | ||
41 | if (body.command === 'remove-dandling-resumable-uploads') { | |
42 | await RemoveDanglingResumableUploadsScheduler.Instance.execute() | |
43 | } | |
44 | ||
45 | return res.status(HttpStatusCode.NO_CONTENT_204).end() | |
46 | } |