1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-04 02:09:37 +02:00

add user agent video stats (#6871)

* add user agent video stats

closes #6832

* Disable indexes, support start/end dates

* move ua parsing to client

* Openapi, inline body request, update tests

---------

Co-authored-by: Chocobozzz <me@florianbigard.com>
This commit is contained in:
kontrollanten 2025-04-07 10:29:59 +02:00 committed by GitHub
parent 96380859ef
commit a7be820abc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
29 changed files with 765 additions and 147 deletions

View file

@ -1,12 +1,27 @@
import { VideoStatsUserAgentDevice } from '@peertube/peertube-models'
import { CONSTRAINTS_FIELDS } from '@server/initializers/constants.js'
import validator from 'validator'
import { exists } from './misc.js'
function isVideoTimeValid (value: number, videoDuration?: number) {
export function isVideoTimeValid (value: number, videoDuration?: number) {
if (value < 0) return false
if (exists(videoDuration) && value > videoDuration) return false
return true
}
export {
isVideoTimeValid
export function isVideoViewEvent (value: string) {
return value === 'seek'
}
export function isVideoViewUAInfo (value: string) {
return validator.default.isLength(value, CONSTRAINTS_FIELDS.VIDEO_VIEW.UA_INFO)
}
// See https://docs.uaparser.dev/info/device/type.html
const devices = new Set<VideoStatsUserAgentDevice>([ 'console', 'embedded', 'mobile', 'smarttv', 'tablet', 'wearable', 'xr', 'desktop' ])
export function toVideoViewUADeviceOrNull (value: VideoStatsUserAgentDevice) {
return devices.has(value)
? value
: null
}