]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/controllers/api/server/debug.ts
Merge branch 'release/3.2.0' into develop
[github/Chocobozzz/PeerTube.git] / server / controllers / api / server / debug.ts
1 import { InboxManager } from '@server/lib/activitypub/inbox-manager'
2 import { RemoveDanglingResumableUploadsScheduler } from '@server/lib/schedulers/remove-dangling-resumable-uploads-scheduler'
3 import { SendDebugCommand } from '@shared/models'
4 import * as express from 'express'
5 import { UserRight } from '../../../../shared/models/users'
6 import { authenticate, ensureUserHasRight } from '../../../middlewares'
7
8 const debugRouter = express.Router()
9
10 debugRouter.get('/debug',
11 authenticate,
12 ensureUserHasRight(UserRight.MANAGE_DEBUG),
13 getDebug
14 )
15
16 debugRouter.post('/debug/run-command',
17 authenticate,
18 ensureUserHasRight(UserRight.MANAGE_DEBUG),
19 runCommand
20 )
21
22 // ---------------------------------------------------------------------------
23
24 export {
25 debugRouter
26 }
27
28 // ---------------------------------------------------------------------------
29
30 function getDebug (req: express.Request, res: express.Response) {
31 return res.json({
32 ip: req.ip,
33 activityPubMessagesWaiting: InboxManager.Instance.getActivityPubMessagesWaiting()
34 })
35 }
36
37 async function runCommand (req: express.Request, res: express.Response) {
38 const body: SendDebugCommand = req.body
39
40 if (body.command === 'remove-dandling-resumable-uploads') {
41 await RemoveDanglingResumableUploadsScheduler.Instance.execute()
42 }
43
44 return res.sendStatus(204)
45 }