]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/extra-utils/videos/video-history.ts
2d751cf148b1c44bf5381f15bdeb22cdd7693d77
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / videos / video-history.ts
1 import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests'
2 import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
3
4 function userWatchVideo (url: string, token: string, videoId: number | string, currentTime: number, statusCodeExpected = 204) {
5 const path = '/api/v1/videos/' + videoId + '/watching'
6 const fields = { currentTime }
7
8 return makePutBodyRequest({ url, path, token, fields, statusCodeExpected })
9 }
10
11 function listMyVideosHistory (url: string, token: string) {
12 const path = '/api/v1/users/me/history/videos'
13
14 return makeGetRequest({
15 url,
16 path,
17 token,
18 statusCodeExpected: HttpStatusCode.OK_200
19 })
20 }
21
22 function removeMyVideosHistory (url: string, token: string, beforeDate?: string) {
23 const path = '/api/v1/users/me/history/videos/remove'
24
25 return makePostBodyRequest({
26 url,
27 path,
28 token,
29 fields: beforeDate ? { beforeDate } : {},
30 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
31 })
32 }
33
34 // ---------------------------------------------------------------------------
35
36 export {
37 userWatchVideo,
38 listMyVideosHistory,
39 removeMyVideosHistory
40 }