2022-08-12 16:41:29 +02:00
|
|
|
import express from 'express'
|
|
|
|
import { body } from 'express-validator'
|
|
|
|
import { isValidPlayerMode } from '@server/helpers/custom-validators/metrics'
|
|
|
|
import { isIdOrUUIDValid, toCompleteUUID } from '@server/helpers/custom-validators/misc'
|
|
|
|
import { CONFIG } from '@server/initializers/config'
|
|
|
|
import { HttpStatusCode, PlaybackMetricCreate } from '@shared/models'
|
|
|
|
import { areValidationErrors, doesVideoExist } from './shared'
|
|
|
|
|
|
|
|
const addPlaybackMetricValidator = [
|
|
|
|
body('resolution')
|
2022-08-17 14:27:04 +02:00
|
|
|
.isInt({ min: 0 }),
|
2022-08-12 16:41:29 +02:00
|
|
|
body('fps')
|
|
|
|
.optional()
|
2022-08-17 14:27:04 +02:00
|
|
|
.isInt({ min: 0 }),
|
2022-08-12 16:41:29 +02:00
|
|
|
body('playerMode')
|
2022-08-17 14:27:04 +02:00
|
|
|
.custom(isValidPlayerMode),
|
2022-08-12 16:41:29 +02:00
|
|
|
|
|
|
|
body('resolutionChanges')
|
2022-08-17 14:27:04 +02:00
|
|
|
.isInt({ min: 0 }),
|
2022-08-12 16:41:29 +02:00
|
|
|
|
|
|
|
body('errors')
|
2022-08-17 14:27:04 +02:00
|
|
|
.isInt({ min: 0 }),
|
2022-08-12 16:41:29 +02:00
|
|
|
|
|
|
|
body('downloadedBytesP2P')
|
2022-08-17 14:27:04 +02:00
|
|
|
.isInt({ min: 0 }),
|
2022-08-12 16:41:29 +02:00
|
|
|
body('downloadedBytesHTTP')
|
2022-08-17 14:27:04 +02:00
|
|
|
.isInt({ min: 0 }),
|
2022-08-12 16:41:29 +02:00
|
|
|
|
|
|
|
body('uploadedBytesP2P')
|
2022-08-17 14:27:04 +02:00
|
|
|
.isInt({ min: 0 }),
|
2022-08-12 16:41:29 +02:00
|
|
|
|
|
|
|
body('videoId')
|
|
|
|
.customSanitizer(toCompleteUUID)
|
|
|
|
.custom(isIdOrUUIDValid),
|
|
|
|
|
|
|
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
|
|
|
if (!CONFIG.OPEN_TELEMETRY.METRICS.ENABLED) return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
|
|
|
|
|
|
|
|
const body: PlaybackMetricCreate = req.body
|
|
|
|
|
|
|
|
if (areValidationErrors(req, res)) return
|
|
|
|
if (!await doesVideoExist(body.videoId, res, 'only-immutable-attributes')) return
|
|
|
|
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
addPlaybackMetricValidator
|
|
|
|
}
|