]>
Commit | Line | Data |
---|---|---|
4c7e60bc | 1 | import { HttpStatusCode, ResultList, Video, 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 | 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 }, | |
a1637fa1 | 52 | implicitToken: true, |
2c27e704 C |
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, | |
a1637fa1 | 66 | implicitToken: true, |
2c27e704 C |
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, | |
a1637fa1 | 80 | implicitToken: true, |
2c27e704 C |
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 }, | |
a1637fa1 | 95 | implicitToken: true, |
2c27e704 C |
96 | defaultExpectedStatus: HttpStatusCode.OK_200 |
97 | }) | |
98 | } | |
99 | } |