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