]>
Commit | Line | Data |
---|---|---|
692ae8c3 | 1 | import { HttpStatusCode, ResultList, VideoChannel } from '@shared/models' |
2c27e704 C |
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 }, | |
a1637fa1 | 16 | implicitToken: true, |
2c27e704 C |
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 | }, | |
a1637fa1 | 36 | implicitToken: true, |
2c27e704 C |
37 | defaultExpectedStatus: HttpStatusCode.OK_200 |
38 | }) | |
39 | } | |
40 | ||
41 | get (options: OverrideCommandOptions & { | |
42 | uri: string | |
43 | }) { | |
44 | const path = '/api/v1/users/me/subscriptions/' + options.uri | |
45 | ||
46 | return this.getRequestBody<VideoChannel>({ | |
47 | ...options, | |
48 | ||
49 | path, | |
a1637fa1 | 50 | implicitToken: true, |
2c27e704 C |
51 | defaultExpectedStatus: HttpStatusCode.OK_200 |
52 | }) | |
53 | } | |
54 | ||
55 | remove (options: OverrideCommandOptions & { | |
56 | uri: string | |
57 | }) { | |
58 | const path = '/api/v1/users/me/subscriptions/' + options.uri | |
59 | ||
60 | return this.deleteRequest({ | |
61 | ...options, | |
62 | ||
63 | path, | |
a1637fa1 | 64 | implicitToken: true, |
2c27e704 C |
65 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 |
66 | }) | |
67 | } | |
68 | ||
69 | exist (options: OverrideCommandOptions & { | |
70 | uris: string[] | |
71 | }) { | |
72 | const path = '/api/v1/users/me/subscriptions/exist' | |
73 | ||
74 | return this.getRequestBody<{ [id: string ]: boolean }>({ | |
75 | ...options, | |
76 | ||
77 | path, | |
78 | query: { 'uris[]': options.uris }, | |
a1637fa1 | 79 | implicitToken: true, |
2c27e704 C |
80 | defaultExpectedStatus: HttpStatusCode.OK_200 |
81 | }) | |
82 | } | |
83 | } |