aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/requests.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-05-15 22:22:03 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-05-20 09:57:40 +0200
commit65fcc3119c334b75dd13bcfdebf186afdc580a8f (patch)
tree4f2158c61a9b7c3f47cfa233d01413b946ee53c0 /server/controllers/api/requests.ts
parentd5f345ed4cfac4e1fa84dcb4fce1cda4d32f9c73 (diff)
downloadPeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.gz
PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.zst
PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.zip
First typescript iteration
Diffstat (limited to 'server/controllers/api/requests.ts')
-rw-r--r--server/controllers/api/requests.ts57
1 files changed, 57 insertions, 0 deletions
diff --git a/server/controllers/api/requests.ts b/server/controllers/api/requests.ts
new file mode 100644
index 000000000..304499a4f
--- /dev/null
+++ b/server/controllers/api/requests.ts
@@ -0,0 +1,57 @@
1import express = require('express')
2import { parallel } from 'async'
3
4import {
5 getRequestScheduler,
6 getRequestVideoQaduScheduler,
7 getRequestVideoEventScheduler
8} from '../../lib'
9import { authenticate, ensureIsAdmin } from '../../middlewares'
10
11const requestsRouter = express.Router()
12
13requestsRouter.get('/stats',
14 authenticate,
15 ensureIsAdmin,
16 getStatsRequests
17)
18
19// ---------------------------------------------------------------------------
20
21export {
22 requestsRouter
23}
24
25// ---------------------------------------------------------------------------
26
27function getStatsRequests (req, res, next) {
28 parallel({
29 requestScheduler: buildRequestSchedulerFunction(getRequestScheduler()),
30 requestVideoQaduScheduler: buildRequestSchedulerFunction(getRequestVideoQaduScheduler()),
31 requestVideoEventScheduler: buildRequestSchedulerFunction(getRequestVideoEventScheduler())
32 }, function (err, result) {
33 if (err) return next(err)
34
35 return res.json(result)
36 })
37}
38
39// ---------------------------------------------------------------------------
40
41function buildRequestSchedulerFunction (requestScheduler) {
42 return function (callback) {
43 requestScheduler.remainingRequestsCount(function (err, count) {
44 if (err) return callback(err)
45
46 const result = {
47 totalRequests: count,
48 requestsLimitPods: requestScheduler.limitPods,
49 requestsLimitPerPod: requestScheduler.limitPerPod,
50 remainingMilliSeconds: requestScheduler.remainingMilliSeconds(),
51 milliSecondsInterval: requestScheduler.requestInterval
52 }
53
54 return callback(null, result)
55 })
56 }
57}