]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/server-commands/videos/history-command.ts
Add ability to delete history element
[github/Chocobozzz/PeerTube.git] / shared / server-commands / videos / history-command.ts
1 import { HttpStatusCode, ResultList, Video } from '@shared/models'
2 import { AbstractCommand, OverrideCommandOptions } from '../shared'
3
4 export class HistoryCommand extends AbstractCommand {
5
6 watchVideo (options: OverrideCommandOptions & {
7 videoId: number | string
8 currentTime: number
9 }) {
10 const { videoId, currentTime } = options
11
12 const path = '/api/v1/videos/' + videoId + '/watching'
13 const fields = { currentTime }
14
15 return this.putBodyRequest({
16 ...options,
17
18 path,
19 fields,
20 implicitToken: true,
21 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
22 })
23 }
24
25 list (options: OverrideCommandOptions & {
26 search?: string
27 } = {}) {
28 const { search } = options
29 const path = '/api/v1/users/me/history/videos'
30
31 return this.getRequestBody<ResultList<Video>>({
32 ...options,
33
34 path,
35 query: {
36 search
37 },
38 implicitToken: true,
39 defaultExpectedStatus: HttpStatusCode.OK_200
40 })
41 }
42
43 removeElement (options: OverrideCommandOptions & {
44 videoId: number
45 }) {
46 const { videoId } = options
47 const path = '/api/v1/users/me/history/videos/' + videoId
48
49 return this.deleteRequest({
50 ...options,
51
52 path,
53 implicitToken: true,
54 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
55 })
56 }
57
58 removeAll (options: OverrideCommandOptions & {
59 beforeDate?: string
60 } = {}) {
61 const { beforeDate } = options
62 const path = '/api/v1/users/me/history/videos/remove'
63
64 return this.postBodyRequest({
65 ...options,
66
67 path,
68 fields: { beforeDate },
69 implicitToken: true,
70 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
71 })
72 }
73 }