2
1

video-stats-command.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { pick } from '@shared/core-utils'
  2. import { HttpStatusCode, VideoStatsOverall, VideoStatsRetention, VideoStatsTimeserie, VideoStatsTimeserieMetric } from '@shared/models'
  3. import { AbstractCommand, OverrideCommandOptions } from '../shared'
  4. export class VideoStatsCommand extends AbstractCommand {
  5. getOverallStats (options: OverrideCommandOptions & {
  6. videoId: number | string
  7. startDate?: string
  8. endDate?: string
  9. }) {
  10. const path = '/api/v1/videos/' + options.videoId + '/stats/overall'
  11. return this.getRequestBody<VideoStatsOverall>({
  12. ...options,
  13. path,
  14. query: pick(options, [ 'startDate', 'endDate' ]),
  15. implicitToken: true,
  16. defaultExpectedStatus: HttpStatusCode.OK_200
  17. })
  18. }
  19. getTimeserieStats (options: OverrideCommandOptions & {
  20. videoId: number | string
  21. metric: VideoStatsTimeserieMetric
  22. startDate?: Date
  23. endDate?: Date
  24. }) {
  25. const path = '/api/v1/videos/' + options.videoId + '/stats/timeseries/' + options.metric
  26. return this.getRequestBody<VideoStatsTimeserie>({
  27. ...options,
  28. path,
  29. query: pick(options, [ 'startDate', 'endDate' ]),
  30. implicitToken: true,
  31. defaultExpectedStatus: HttpStatusCode.OK_200
  32. })
  33. }
  34. getRetentionStats (options: OverrideCommandOptions & {
  35. videoId: number | string
  36. }) {
  37. const path = '/api/v1/videos/' + options.videoId + '/stats/retention'
  38. return this.getRequestBody<VideoStatsRetention>({
  39. ...options,
  40. path,
  41. implicitToken: true,
  42. defaultExpectedStatus: HttpStatusCode.OK_200
  43. })
  44. }
  45. }