diff options
Diffstat (limited to 'server/middlewares/validators/metrics.ts')
-rw-r--r-- | server/middlewares/validators/metrics.ts | 60 |
1 files changed, 0 insertions, 60 deletions
diff --git a/server/middlewares/validators/metrics.ts b/server/middlewares/validators/metrics.ts deleted file mode 100644 index 986b30a19..000000000 --- a/server/middlewares/validators/metrics.ts +++ /dev/null | |||
@@ -1,60 +0,0 @@ | |||
1 | import express from 'express' | ||
2 | import { body } from 'express-validator' | ||
3 | import { isValidPlayerMode } from '@server/helpers/custom-validators/metrics' | ||
4 | import { isIdOrUUIDValid, toCompleteUUID } from '@server/helpers/custom-validators/misc' | ||
5 | import { CONFIG } from '@server/initializers/config' | ||
6 | import { HttpStatusCode, PlaybackMetricCreate } from '@shared/models' | ||
7 | import { areValidationErrors, doesVideoExist } from './shared' | ||
8 | |||
9 | const addPlaybackMetricValidator = [ | ||
10 | body('resolution') | ||
11 | .isInt({ min: 0 }), | ||
12 | body('fps') | ||
13 | .optional() | ||
14 | .isInt({ min: 0 }), | ||
15 | |||
16 | body('p2pPeers') | ||
17 | .optional() | ||
18 | .isInt({ min: 0 }), | ||
19 | |||
20 | body('p2pEnabled') | ||
21 | .isBoolean(), | ||
22 | |||
23 | body('playerMode') | ||
24 | .custom(isValidPlayerMode), | ||
25 | |||
26 | body('resolutionChanges') | ||
27 | .isInt({ min: 0 }), | ||
28 | |||
29 | body('errors') | ||
30 | .isInt({ min: 0 }), | ||
31 | |||
32 | body('downloadedBytesP2P') | ||
33 | .isInt({ min: 0 }), | ||
34 | body('downloadedBytesHTTP') | ||
35 | .isInt({ min: 0 }), | ||
36 | |||
37 | body('uploadedBytesP2P') | ||
38 | .isInt({ min: 0 }), | ||
39 | |||
40 | body('videoId') | ||
41 | .customSanitizer(toCompleteUUID) | ||
42 | .custom(isIdOrUUIDValid), | ||
43 | |||
44 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
45 | if (!CONFIG.OPEN_TELEMETRY.METRICS.ENABLED) return res.sendStatus(HttpStatusCode.NO_CONTENT_204) | ||
46 | |||
47 | const body: PlaybackMetricCreate = req.body | ||
48 | |||
49 | if (areValidationErrors(req, res)) return | ||
50 | if (!await doesVideoExist(body.videoId, res, 'only-immutable-attributes')) return | ||
51 | |||
52 | return next() | ||
53 | } | ||
54 | ] | ||
55 | |||
56 | // --------------------------------------------------------------------------- | ||
57 | |||
58 | export { | ||
59 | addPlaybackMetricValidator | ||
60 | } | ||