diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-08 16:21:42 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-20 15:27:18 +0200 |
commit | 313228e9c3b5bcef5391228c9b949d05d32ad7bb (patch) | |
tree | d2f39a2bd32ef093224c594d72219809504321b7 /shared/extra-utils/videos/history-command.ts | |
parent | e6346d59e63135cf012ed18c102d3b0179ef565f (diff) | |
download | PeerTube-313228e9c3b5bcef5391228c9b949d05d32ad7bb.tar.gz PeerTube-313228e9c3b5bcef5391228c9b949d05d32ad7bb.tar.zst PeerTube-313228e9c3b5bcef5391228c9b949d05d32ad7bb.zip |
Introduce history command
Diffstat (limited to 'shared/extra-utils/videos/history-command.ts')
-rw-r--r-- | shared/extra-utils/videos/history-command.ts | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/shared/extra-utils/videos/history-command.ts b/shared/extra-utils/videos/history-command.ts new file mode 100644 index 000000000..8a144a312 --- /dev/null +++ b/shared/extra-utils/videos/history-command.ts | |||
@@ -0,0 +1,59 @@ | |||
1 | import { ResultList, Video } from '@shared/models' | ||
2 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' | ||
3 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
4 | |||
5 | export class HistoryCommand extends AbstractCommand { | ||
6 | |||
7 | wathVideo (options: OverrideCommandOptions & { | ||
8 | videoId: number | string | ||
9 | currentTime: number | ||
10 | }) { | ||
11 | const { videoId, currentTime } = options | ||
12 | |||
13 | const path = '/api/v1/videos/' + videoId + '/watching' | ||
14 | const fields = { currentTime } | ||
15 | |||
16 | return this.putBodyRequest({ | ||
17 | ...options, | ||
18 | |||
19 | path, | ||
20 | fields, | ||
21 | implicitToken: true, | ||
22 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
23 | }) | ||
24 | } | ||
25 | |||
26 | list (options: OverrideCommandOptions & { | ||
27 | search?: string | ||
28 | } = {}) { | ||
29 | const { search } = options | ||
30 | const path = '/api/v1/users/me/history/videos' | ||
31 | |||
32 | return this.getRequestBody<ResultList<Video>>({ | ||
33 | ...options, | ||
34 | |||
35 | path, | ||
36 | query: { | ||
37 | search | ||
38 | }, | ||
39 | implicitToken: true, | ||
40 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
41 | }) | ||
42 | } | ||
43 | |||
44 | remove (options: OverrideCommandOptions & { | ||
45 | beforeDate?: string | ||
46 | } = {}) { | ||
47 | const { beforeDate } = options | ||
48 | const path = '/api/v1/users/me/history/videos/remove' | ||
49 | |||
50 | return this.postBodyRequest({ | ||
51 | ...options, | ||
52 | |||
53 | path, | ||
54 | fields: { beforeDate }, | ||
55 | implicitToken: true, | ||
56 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
57 | }) | ||
58 | } | ||
59 | } | ||