diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-07 16:40:49 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-20 15:27:17 +0200 |
commit | 2c27e70471120c92e0bc8c8114141fbb31ff98ac (patch) | |
tree | f52d89adc0351168fd1d89cbc07652e1408caaf2 /shared/extra-utils/users/subscriptions-command.ts | |
parent | 5f8bd4cbb178290da7d8f81e996f19f0eccc8e4c (diff) | |
download | PeerTube-2c27e70471120c92e0bc8c8114141fbb31ff98ac.tar.gz PeerTube-2c27e70471120c92e0bc8c8114141fbb31ff98ac.tar.zst PeerTube-2c27e70471120c92e0bc8c8114141fbb31ff98ac.zip |
Introduce subscriptions command
Diffstat (limited to 'shared/extra-utils/users/subscriptions-command.ts')
-rw-r--r-- | shared/extra-utils/users/subscriptions-command.ts | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/shared/extra-utils/users/subscriptions-command.ts b/shared/extra-utils/users/subscriptions-command.ts new file mode 100644 index 000000000..94d2af67a --- /dev/null +++ b/shared/extra-utils/users/subscriptions-command.ts | |||
@@ -0,0 +1,94 @@ | |||
1 | import { ResultList, Video, VideoChannel } from '@shared/models' | ||
2 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' | ||
3 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
4 | |||
5 | export class SubscriptionsCommand extends AbstractCommand { | ||
6 | |||
7 | add (options: OverrideCommandOptions & { | ||
8 | targetUri: string | ||
9 | }) { | ||
10 | const path = '/api/v1/users/me/subscriptions' | ||
11 | |||
12 | return this.postBodyRequest({ | ||
13 | ...options, | ||
14 | |||
15 | path, | ||
16 | fields: { uri: options.targetUri }, | ||
17 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
18 | }) | ||
19 | } | ||
20 | |||
21 | list (options: OverrideCommandOptions & { | ||
22 | sort?: string // default -createdAt | ||
23 | search?: string | ||
24 | } = {}) { | ||
25 | const { sort = '-createdAt', search } = options | ||
26 | const path = '/api/v1/users/me/subscriptions' | ||
27 | |||
28 | return this.getRequestBody<ResultList<VideoChannel>>({ | ||
29 | ...options, | ||
30 | |||
31 | path, | ||
32 | query: { | ||
33 | sort, | ||
34 | search | ||
35 | }, | ||
36 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
37 | }) | ||
38 | } | ||
39 | |||
40 | listVideos (options: OverrideCommandOptions & { | ||
41 | sort?: string // default -createdAt | ||
42 | } = {}) { | ||
43 | const { sort = '-createdAt' } = options | ||
44 | const path = '/api/v1/users/me/subscriptions/videos' | ||
45 | |||
46 | return this.getRequestBody<ResultList<Video>>({ | ||
47 | ...options, | ||
48 | |||
49 | path, | ||
50 | query: { sort }, | ||
51 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
52 | }) | ||
53 | } | ||
54 | |||
55 | get (options: OverrideCommandOptions & { | ||
56 | uri: string | ||
57 | }) { | ||
58 | const path = '/api/v1/users/me/subscriptions/' + options.uri | ||
59 | |||
60 | return this.getRequestBody<VideoChannel>({ | ||
61 | ...options, | ||
62 | |||
63 | path, | ||
64 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
65 | }) | ||
66 | } | ||
67 | |||
68 | remove (options: OverrideCommandOptions & { | ||
69 | uri: string | ||
70 | }) { | ||
71 | const path = '/api/v1/users/me/subscriptions/' + options.uri | ||
72 | |||
73 | return this.deleteRequest({ | ||
74 | ...options, | ||
75 | |||
76 | path, | ||
77 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
78 | }) | ||
79 | } | ||
80 | |||
81 | exist (options: OverrideCommandOptions & { | ||
82 | uris: string[] | ||
83 | }) { | ||
84 | const path = '/api/v1/users/me/subscriptions/exist' | ||
85 | |||
86 | return this.getRequestBody<{ [id: string ]: boolean }>({ | ||
87 | ...options, | ||
88 | |||
89 | path, | ||
90 | query: { 'uris[]': options.uris }, | ||
91 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
92 | }) | ||
93 | } | ||
94 | } | ||