aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/videos/history-command.ts
blob: 41afc6bc6a306bf0be804424558c62e28868bced (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { HttpStatusCode } from '@shared/models'
import { ResultList, Video } from '@shared/models'
import { AbstractCommand, OverrideCommandOptions } from '../shared'

export class HistoryCommand extends AbstractCommand {

  wathVideo (options: OverrideCommandOptions & {
    videoId: number | string
    currentTime: number
  }) {
    const { videoId, currentTime } = options

    const path = '/api/v1/videos/' + videoId + '/watching'
    const fields = { currentTime }

    return this.putBodyRequest({
      ...options,

      path,
      fields,
      implicitToken: true,
      defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
    })
  }

  list (options: OverrideCommandOptions & {
    search?: string
  } = {}) {
    const { search } = options
    const path = '/api/v1/users/me/history/videos'

    return this.getRequestBody<ResultList<Video>>({
      ...options,

      path,
      query: {
        search
      },
      implicitToken: true,
      defaultExpectedStatus: HttpStatusCode.OK_200
    })
  }

  remove (options: OverrideCommandOptions & {
    beforeDate?: string
  } = {}) {
    const { beforeDate } = options
    const path = '/api/v1/users/me/history/videos/remove'

    return this.postBodyRequest({
      ...options,

      path,
      fields: { beforeDate },
      implicitToken: true,
      defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
    })
  }
}