mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-03 09:49:20 +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:
parent
96380859ef
commit
a7be820abc
29 changed files with 765 additions and 147 deletions
|
@ -4,17 +4,19 @@ import {
|
|||
VideoStatsOverall,
|
||||
VideoStatsRetention,
|
||||
VideoStatsTimeserie,
|
||||
VideoStatsTimeserieMetric
|
||||
VideoStatsTimeserieMetric,
|
||||
VideoStatsUserAgent
|
||||
} from '@peertube/peertube-models'
|
||||
import { AbstractCommand, OverrideCommandOptions } from '../shared/index.js'
|
||||
|
||||
export class VideoStatsCommand extends AbstractCommand {
|
||||
|
||||
getOverallStats (options: OverrideCommandOptions & {
|
||||
videoId: number | string
|
||||
startDate?: string
|
||||
endDate?: string
|
||||
}) {
|
||||
getOverallStats (
|
||||
options: OverrideCommandOptions & {
|
||||
videoId: number | string
|
||||
startDate?: string
|
||||
endDate?: string
|
||||
}
|
||||
) {
|
||||
const path = '/api/v1/videos/' + options.videoId + '/stats/overall'
|
||||
|
||||
return this.getRequestBody<VideoStatsOverall>({
|
||||
|
@ -28,12 +30,34 @@ export class VideoStatsCommand extends AbstractCommand {
|
|||
})
|
||||
}
|
||||
|
||||
getTimeserieStats (options: OverrideCommandOptions & {
|
||||
videoId: number | string
|
||||
metric: VideoStatsTimeserieMetric
|
||||
startDate?: Date
|
||||
endDate?: Date
|
||||
}) {
|
||||
getUserAgentStats (
|
||||
options: OverrideCommandOptions & {
|
||||
videoId: number | string
|
||||
startDate?: string
|
||||
endDate?: string
|
||||
}
|
||||
) {
|
||||
const path = '/api/v1/videos/' + options.videoId + '/stats/user-agent'
|
||||
|
||||
return this.getRequestBody<VideoStatsUserAgent>({
|
||||
...options,
|
||||
path,
|
||||
|
||||
query: pick(options, [ 'startDate', 'endDate' ]),
|
||||
|
||||
implicitToken: true,
|
||||
defaultExpectedStatus: HttpStatusCode.OK_200
|
||||
})
|
||||
}
|
||||
|
||||
getTimeserieStats (
|
||||
options: OverrideCommandOptions & {
|
||||
videoId: number | string
|
||||
metric: VideoStatsTimeserieMetric
|
||||
startDate?: Date
|
||||
endDate?: Date
|
||||
}
|
||||
) {
|
||||
const path = '/api/v1/videos/' + options.videoId + '/stats/timeseries/' + options.metric
|
||||
|
||||
return this.getRequestBody<VideoStatsTimeserie>({
|
||||
|
@ -46,9 +70,11 @@ export class VideoStatsCommand extends AbstractCommand {
|
|||
})
|
||||
}
|
||||
|
||||
getRetentionStats (options: OverrideCommandOptions & {
|
||||
videoId: number | string
|
||||
}) {
|
||||
getRetentionStats (
|
||||
options: OverrideCommandOptions & {
|
||||
videoId: number | string
|
||||
}
|
||||
) {
|
||||
const path = '/api/v1/videos/' + options.videoId + '/stats/retention'
|
||||
|
||||
return this.getRequestBody<VideoStatsRetention>({
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */
|
||||
import { HttpStatusCode, VideoViewEvent } from '@peertube/peertube-models'
|
||||
import { pick } from '@peertube/peertube-core-utils'
|
||||
import { HttpStatusCode, VideoView, VideoViewEvent } from '@peertube/peertube-models'
|
||||
import { AbstractCommand, OverrideCommandOptions } from '../shared/index.js'
|
||||
|
||||
export class ViewsCommand extends AbstractCommand {
|
||||
|
||||
view (options: OverrideCommandOptions & {
|
||||
id: number | string
|
||||
currentTime: number
|
||||
viewEvent?: VideoViewEvent
|
||||
xForwardedFor?: string
|
||||
sessionId?: string
|
||||
}) {
|
||||
const { id, xForwardedFor, viewEvent, currentTime, sessionId } = options
|
||||
view (
|
||||
options: OverrideCommandOptions & VideoView & {
|
||||
id: number | string
|
||||
xForwardedFor?: string
|
||||
}
|
||||
) {
|
||||
const { id, xForwardedFor } = options
|
||||
const path = '/api/v1/videos/' + id + '/views'
|
||||
|
||||
return this.postBodyRequest({
|
||||
|
@ -19,31 +18,30 @@ export class ViewsCommand extends AbstractCommand {
|
|||
|
||||
path,
|
||||
xForwardedFor,
|
||||
fields: {
|
||||
currentTime,
|
||||
viewEvent,
|
||||
sessionId
|
||||
},
|
||||
fields: pick(options, [ 'currentTime', 'viewEvent', 'sessionId', 'client', 'device', 'operatingSystem' ]),
|
||||
implicitToken: false,
|
||||
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
|
||||
})
|
||||
}
|
||||
|
||||
async simulateView (options: OverrideCommandOptions & {
|
||||
id: number | string
|
||||
xForwardedFor?: string
|
||||
sessionId?: string
|
||||
}) {
|
||||
async simulateView (
|
||||
options: OverrideCommandOptions & Omit<VideoView, 'currentTime'> & {
|
||||
id: number | string
|
||||
xForwardedFor?: string
|
||||
}
|
||||
) {
|
||||
await this.view({ ...options, currentTime: 0 })
|
||||
await this.view({ ...options, currentTime: 5 })
|
||||
}
|
||||
|
||||
async simulateViewer (options: OverrideCommandOptions & {
|
||||
id: number | string
|
||||
currentTimes: number[]
|
||||
xForwardedFor?: string
|
||||
sessionId?: string
|
||||
}) {
|
||||
async simulateViewer (
|
||||
options: OverrideCommandOptions & {
|
||||
id: number | string
|
||||
currentTimes: number[]
|
||||
xForwardedFor?: string
|
||||
sessionId?: string
|
||||
}
|
||||
) {
|
||||
let viewEvent: VideoViewEvent = 'seek'
|
||||
|
||||
for (const currentTime of options.currentTimes) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue