]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+stats/video/video-stats.service.ts
Add filter by start/end date overall stats in api
[github/Chocobozzz/PeerTube.git] / client / src / app / +stats / video / video-stats.service.ts
CommitLineData
384ba8b7
C
1import { catchError } from 'rxjs'
2import { environment } from 'src/environments/environment'
3eda9b77 3import { HttpClient, HttpParams } from '@angular/common/http'
384ba8b7
C
4import { Injectable } from '@angular/core'
5import { RestExtractor } from '@app/core'
6import { VideoService } from '@app/shared/shared-main'
7import { VideoStatsOverall, VideoStatsRetention, VideoStatsTimeserie, VideoStatsTimeserieMetric } from '@shared/models/videos'
8
9@Injectable({
10 providedIn: 'root'
11})
12export class VideoStatsService {
13 static BASE_VIDEO_STATS_URL = environment.apiUrl + '/api/v1/videos/'
14
15 constructor (
16 private authHttp: HttpClient,
17 private restExtractor: RestExtractor
18 ) { }
19
20 getOverallStats (videoId: string) {
21 return this.authHttp.get<VideoStatsOverall>(VideoService.BASE_VIDEO_URL + '/' + videoId + '/stats/overall')
22 .pipe(catchError(err => this.restExtractor.handleError(err)))
23 }
24
3eda9b77
C
25 getTimeserieStats (options: {
26 videoId: string
27 metric: VideoStatsTimeserieMetric
28 startDate?: Date
29 endDate?: Date
30 }) {
31 const { videoId, metric, startDate, endDate } = options
32
33 let params = new HttpParams()
34 if (startDate) params = params.append('startDate', startDate.toISOString())
35 if (endDate) params = params.append('endDate', endDate.toISOString())
36
37 return this.authHttp.get<VideoStatsTimeserie>(VideoService.BASE_VIDEO_URL + '/' + videoId + '/stats/timeseries/' + metric, { params })
384ba8b7
C
38 .pipe(catchError(err => this.restExtractor.handleError(err)))
39 }
40
41 getRetentionStats (videoId: string) {
42 return this.authHttp.get<VideoStatsRetention>(VideoService.BASE_VIDEO_URL + '/' + videoId + '/stats/retention')
43 .pipe(catchError(err => this.restExtractor.handleError(err)))
44 }
45}