]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/server/debug.ts
Improve viewer counter
[github/Chocobozzz/PeerTube.git] / server / controllers / api / server / debug.ts
index ff0d9ca3caf070370fe6036dbce19a2b6b62d7f2..e09510dc3754cfb08657dcb03a1da188a91aba53 100644 (file)
@@ -1,7 +1,10 @@
+import express from 'express'
 import { InboxManager } from '@server/lib/activitypub/inbox-manager'
 import { RemoveDanglingResumableUploadsScheduler } from '@server/lib/schedulers/remove-dangling-resumable-uploads-scheduler'
-import { SendDebugCommand } from '@shared/models'
-import * as express from 'express'
+import { VideoViewsBufferScheduler } from '@server/lib/schedulers/video-views-buffer-scheduler'
+import { VideoViewsManager } from '@server/lib/views/video-views-manager'
+import { Debug, SendDebugCommand } from '@shared/models'
+import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes'
 import { UserRight } from '../../../../shared/models/users'
 import { authenticate, ensureUserHasRight } from '../../../middlewares'
 
@@ -31,15 +34,19 @@ function getDebug (req: express.Request, res: express.Response) {
   return res.json({
     ip: req.ip,
     activityPubMessagesWaiting: InboxManager.Instance.getActivityPubMessagesWaiting()
-  })
+  } as Debug)
 }
 
 async function runCommand (req: express.Request, res: express.Response) {
   const body: SendDebugCommand = req.body
 
-  if (body.command === 'remove-dandling-resumable-uploads') {
-    await RemoveDanglingResumableUploadsScheduler.Instance.execute()
+  const processors: { [id in SendDebugCommand['command']]: () => Promise<any> } = {
+    'remove-dandling-resumable-uploads': () => RemoveDanglingResumableUploadsScheduler.Instance.execute(),
+    'process-video-views-buffer': () => VideoViewsBufferScheduler.Instance.execute(),
+    'process-video-viewers': () => VideoViewsManager.Instance.processViewerStats()
   }
 
-  return res.sendStatus(204)
+  await processors[body.command]()
+
+  return res.status(HttpStatusCode.NO_CONTENT_204).end()
 }