]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/server-commands/videos/video-stats-command.ts
Bumped to version v5.2.1
[github/Chocobozzz/PeerTube.git] / shared / server-commands / videos / video-stats-command.ts
1 import { pick } from '@shared/core-utils'
2 import { HttpStatusCode, VideoStatsOverall, VideoStatsRetention, VideoStatsTimeserie, VideoStatsTimeserieMetric } from '@shared/models'
3 import { AbstractCommand, OverrideCommandOptions } from '../shared'
4
5 export class VideoStatsCommand extends AbstractCommand {
6
7 getOverallStats (options: OverrideCommandOptions & {
8 videoId: number | string
9 startDate?: string
10 endDate?: string
11 }) {
12 const path = '/api/v1/videos/' + options.videoId + '/stats/overall'
13
14 return this.getRequestBody<VideoStatsOverall>({
15 ...options,
16 path,
17
18 query: pick(options, [ 'startDate', 'endDate' ]),
19
20 implicitToken: true,
21 defaultExpectedStatus: HttpStatusCode.OK_200
22 })
23 }
24
25 getTimeserieStats (options: OverrideCommandOptions & {
26 videoId: number | string
27 metric: VideoStatsTimeserieMetric
28 startDate?: Date
29 endDate?: Date
30 }) {
31 const path = '/api/v1/videos/' + options.videoId + '/stats/timeseries/' + options.metric
32
33 return this.getRequestBody<VideoStatsTimeserie>({
34 ...options,
35 path,
36
37 query: pick(options, [ 'startDate', 'endDate' ]),
38 implicitToken: true,
39 defaultExpectedStatus: HttpStatusCode.OK_200
40 })
41 }
42
43 getRetentionStats (options: OverrideCommandOptions & {
44 videoId: number | string
45 }) {
46 const path = '/api/v1/videos/' + options.videoId + '/stats/retention'
47
48 return this.getRequestBody<VideoStatsRetention>({
49 ...options,
50 path,
51
52 implicitToken: true,
53 defaultExpectedStatus: HttpStatusCode.OK_200
54 })
55 }
56 }