aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/videos/video-history.ts
blob: dc7095b4d7181c817c6ea7a4f352660a62fa5374 (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
import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests'

function userWatchVideo (url: string, token: string, videoId: number | string, currentTime: number, statusCodeExpected = 204) {
  const path = '/api/v1/videos/' + videoId + '/watching'
  const fields = { currentTime }

  return makePutBodyRequest({ url, path, token, fields, statusCodeExpected })
}

function listMyVideosHistory (url: string, token: string) {
  const path = '/api/v1/users/me/history/videos'

  return makeGetRequest({
    url,
    path,
    token,
    statusCodeExpected: 200
  })
}

function removeMyVideosHistory (url: string, token: string, beforeDate?: string) {
  const path = '/api/v1/users/me/history/videos/remove'

  return makePostBodyRequest({
    url,
    path,
    token,
    fields: beforeDate ? { beforeDate } : {},
    statusCodeExpected: 204
  })
}

// ---------------------------------------------------------------------------

export {
  userWatchVideo,
  listMyVideosHistory,
  removeMyVideosHistory
}