]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/server-commands/videos/video-stats-command.ts
Add ability to set start/end date to timeserie
[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 }) {
10 const path = '/api/v1/videos/' + options.videoId + '/stats/overall'
11
12 return this.getRequestBody<VideoStatsOverall>({
13 ...options,
14 path,
15
16 implicitToken: true,
17 defaultExpectedStatus: HttpStatusCode.OK_200
18 })
19 }
20
21 getTimeserieStats (options: OverrideCommandOptions & {
22 videoId: number | string
23 metric: VideoStatsTimeserieMetric
24 startDate?: Date
25 endDate?: Date
26 }) {
27 const path = '/api/v1/videos/' + options.videoId + '/stats/timeseries/' + options.metric
28
29 return this.getRequestBody<VideoStatsTimeserie>({
30 ...options,
31 path,
32
33 query: pick(options, [ 'startDate', 'endDate' ]),
34 implicitToken: true,
35 defaultExpectedStatus: HttpStatusCode.OK_200
36 })
37 }
38
39 getRetentionStats (options: OverrideCommandOptions & {
40 videoId: number | string
41 }) {
42 const path = '/api/v1/videos/' + options.videoId + '/stats/retention'
43
44 return this.getRequestBody<VideoStatsRetention>({
45 ...options,
46 path,
47
48 implicitToken: true,
49 defaultExpectedStatus: HttpStatusCode.OK_200
50 })
51 }
52 }