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'
9 const addPlaybackMetricValidator = [
16 .custom(isValidPlayerMode),
18 body('resolutionChanges')
24 body('downloadedBytesP2P')
26 body('downloadedBytesHTTP')
29 body('uploadedBytesP2P')
33 .customSanitizer(toCompleteUUID)
34 .custom(isIdOrUUIDValid),
36 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
37 if (!CONFIG.OPEN_TELEMETRY.METRICS.ENABLED) return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
39 const body: PlaybackMetricCreate = req.body
41 if (areValidationErrors(req, res)) return
42 if (!await doesVideoExist(body.videoId, res, 'only-immutable-attributes')) return
48 // ---------------------------------------------------------------------------
51 addPlaybackMetricValidator