]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/controllers/api/server/debug.ts
Prepare changelog
[github/Chocobozzz/PeerTube.git] / server / controllers / api / server / debug.ts
... / ...
CommitLineData
1import express from 'express'
2import { InboxManager } from '@server/lib/activitypub/inbox-manager'
3import { RemoveDanglingResumableUploadsScheduler } from '@server/lib/schedulers/remove-dangling-resumable-uploads-scheduler'
4import { Debug, SendDebugCommand } from '@shared/models'
5import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes'
6import { UserRight } from '../../../../shared/models/users'
7import { authenticate, ensureUserHasRight } from '../../../middlewares'
8
9const debugRouter = express.Router()
10
11debugRouter.get('/debug',
12 authenticate,
13 ensureUserHasRight(UserRight.MANAGE_DEBUG),
14 getDebug
15)
16
17debugRouter.post('/debug/run-command',
18 authenticate,
19 ensureUserHasRight(UserRight.MANAGE_DEBUG),
20 runCommand
21)
22
23// ---------------------------------------------------------------------------
24
25export {
26 debugRouter
27}
28
29// ---------------------------------------------------------------------------
30
31function 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
38async 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}