diff options
Diffstat (limited to 'shared/extra-utils/users/subscriptions-command.ts')
-rw-r--r-- | shared/extra-utils/users/subscriptions-command.ts | 99 |
1 files changed, 99 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..edc60e612 --- /dev/null +++ b/shared/extra-utils/users/subscriptions-command.ts | |||
@@ -0,0 +1,99 @@ | |||
1 | import { HttpStatusCode, ResultList, Video, VideoChannel } from '@shared/models' | ||
2 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
3 | |||
4 | export class SubscriptionsCommand extends AbstractCommand { | ||
5 | |||
6 | add (options: OverrideCommandOptions & { | ||
7 | targetUri: string | ||
8 | }) { | ||
9 | const path = '/api/v1/users/me/subscriptions' | ||
10 | |||
11 | return this.postBodyRequest({ | ||
12 | ...options, | ||
13 | |||
14 | path, | ||
15 | fields: { uri: options.targetUri }, | ||
16 | implicitToken: true, | ||
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 | implicitToken: true, | ||
37 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
38 | }) | ||
39 | } | ||
40 | |||
41 | listVideos (options: OverrideCommandOptions & { | ||
42 | sort?: string // default -createdAt | ||
43 | } = {}) { | ||
44 | const { sort = '-createdAt' } = options | ||
45 | const path = '/api/v1/users/me/subscriptions/videos' | ||
46 | |||
47 | return this.getRequestBody<ResultList<Video>>({ | ||
48 | ...options, | ||
49 | |||
50 | path, | ||
51 | query: { sort }, | ||
52 | implicitToken: true, | ||
53 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
54 | }) | ||
55 | } | ||
56 | |||
57 | get (options: OverrideCommandOptions & { | ||
58 | uri: string | ||
59 | }) { | ||
60 | const path = '/api/v1/users/me/subscriptions/' + options.uri | ||
61 | |||
62 | return this.getRequestBody<VideoChannel>({ | ||
63 | ...options, | ||
64 | |||
65 | path, | ||
66 | implicitToken: true, | ||
67 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
68 | }) | ||
69 | } | ||
70 | |||
71 | remove (options: OverrideCommandOptions & { | ||
72 | uri: string | ||
73 | }) { | ||
74 | const path = '/api/v1/users/me/subscriptions/' + options.uri | ||
75 | |||
76 | return this.deleteRequest({ | ||
77 | ...options, | ||
78 | |||
79 | path, | ||
80 | implicitToken: true, | ||
81 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
82 | }) | ||
83 | } | ||
84 | |||
85 | exist (options: OverrideCommandOptions & { | ||
86 | uris: string[] | ||
87 | }) { | ||
88 | const path = '/api/v1/users/me/subscriptions/exist' | ||
89 | |||
90 | return this.getRequestBody<{ [id: string ]: boolean }>({ | ||
91 | ...options, | ||
92 | |||
93 | path, | ||
94 | query: { 'uris[]': options.uris }, | ||
95 | implicitToken: true, | ||
96 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
97 | }) | ||
98 | } | ||
99 | } | ||