2022-08-12 16:41:29 +02:00
|
|
|
import express from 'express'
|
|
|
|
import { body } from 'express-validator'
|
2023-07-31 14:34:36 +02:00
|
|
|
import { isValidPlayerMode } from '@server/helpers/custom-validators/metrics.js'
|
|
|
|
import { isIdOrUUIDValid, toCompleteUUID } from '@server/helpers/custom-validators/misc.js'
|
|
|
|
import { CONFIG } from '@server/initializers/config.js'
|
|
|
|
import { HttpStatusCode, PlaybackMetricCreate } from '@peertube/peertube-models'
|
|
|
|
import { areValidationErrors, doesVideoExist } from './shared/index.js'
|
2022-08-12 16:41:29 +02:00
|
|
|
|
|
|
|
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 }),
|
2023-07-20 12:06:39 +02:00
|
|
|
|
2023-07-21 11:42:52 +02:00
|
|
|
body('p2pPeers')
|
2023-07-20 12:06:39 +02:00
|
|
|
.optional()
|
|
|
|
.isInt({ min: 0 }),
|
|
|
|
|
|
|
|
body('p2pEnabled')
|
|
|
|
.isBoolean(),
|
|
|
|
|
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
|
|
|
|
2024-08-08 14:27:19 +02:00
|
|
|
body('bufferStalled')
|
|
|
|
.optional()
|
|
|
|
.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
|
2024-04-26 08:58:35 +02:00
|
|
|
if (!await doesVideoExist(body.videoId, res, 'unsafe-only-immutable-attributes')) return
|
2022-08-12 16:41:29 +02:00
|
|
|
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
addPlaybackMetricValidator
|
|
|
|
}
|