]>
Commit | Line | Data |
---|---|---|
b033851f | 1 | import { pick } from '@shared/core-utils' |
c55e3d72 C |
2 | import { |
3 | ActorFollow, | |
4 | HttpStatusCode, | |
5 | ResultList, | |
6 | VideoChannel, | |
7 | VideoChannelCreate, | |
8 | VideoChannelCreateResult, | |
a3b472a1 C |
9 | VideoChannelUpdate, |
10 | VideosImportInChannelCreate | |
c55e3d72 | 11 | } from '@shared/models' |
a5461888 C |
12 | import { unwrapBody } from '../requests' |
13 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | |
14 | ||
15 | export class ChannelsCommand extends AbstractCommand { | |
16 | ||
17 | list (options: OverrideCommandOptions & { | |
18 | start?: number | |
19 | count?: number | |
20 | sort?: string | |
21 | withStats?: boolean | |
22 | } = {}) { | |
23 | const path = '/api/v1/video-channels' | |
24 | ||
25 | return this.getRequestBody<ResultList<VideoChannel>>({ | |
26 | ...options, | |
27 | ||
28 | path, | |
29 | query: pick(options, [ 'start', 'count', 'sort', 'withStats' ]), | |
30 | implicitToken: false, | |
31 | defaultExpectedStatus: HttpStatusCode.OK_200 | |
32 | }) | |
33 | } | |
34 | ||
35 | listByAccount (options: OverrideCommandOptions & { | |
36 | accountName: string | |
37 | start?: number | |
38 | count?: number | |
39 | sort?: string | |
40 | withStats?: boolean | |
41 | search?: string | |
42 | }) { | |
43 | const { accountName, sort = 'createdAt' } = options | |
44 | const path = '/api/v1/accounts/' + accountName + '/video-channels' | |
45 | ||
46 | return this.getRequestBody<ResultList<VideoChannel>>({ | |
47 | ...options, | |
48 | ||
49 | path, | |
50 | query: { sort, ...pick(options, [ 'start', 'count', 'withStats', 'search' ]) }, | |
51 | implicitToken: false, | |
52 | defaultExpectedStatus: HttpStatusCode.OK_200 | |
53 | }) | |
54 | } | |
55 | ||
56 | async create (options: OverrideCommandOptions & { | |
4beda9e1 | 57 | attributes: Partial<VideoChannelCreate> |
a5461888 C |
58 | }) { |
59 | const path = '/api/v1/video-channels/' | |
60 | ||
61 | // Default attributes | |
62 | const defaultAttributes = { | |
63 | displayName: 'my super video channel', | |
64 | description: 'my super channel description', | |
65 | support: 'my super channel support' | |
66 | } | |
67 | const attributes = { ...defaultAttributes, ...options.attributes } | |
68 | ||
69 | const body = await unwrapBody<{ videoChannel: VideoChannelCreateResult }>(this.postBodyRequest({ | |
70 | ...options, | |
71 | ||
72 | path, | |
73 | fields: attributes, | |
74 | implicitToken: true, | |
75 | defaultExpectedStatus: HttpStatusCode.OK_200 | |
76 | })) | |
77 | ||
78 | return body.videoChannel | |
79 | } | |
80 | ||
81 | update (options: OverrideCommandOptions & { | |
82 | channelName: string | |
83 | attributes: VideoChannelUpdate | |
84 | }) { | |
85 | const { channelName, attributes } = options | |
86 | const path = '/api/v1/video-channels/' + channelName | |
87 | ||
88 | return this.putBodyRequest({ | |
89 | ...options, | |
90 | ||
91 | path, | |
92 | fields: attributes, | |
93 | implicitToken: true, | |
94 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | |
95 | }) | |
96 | } | |
97 | ||
98 | delete (options: OverrideCommandOptions & { | |
99 | channelName: string | |
100 | }) { | |
101 | const path = '/api/v1/video-channels/' + options.channelName | |
102 | ||
103 | return this.deleteRequest({ | |
104 | ...options, | |
105 | ||
106 | path, | |
107 | implicitToken: true, | |
108 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | |
109 | }) | |
110 | } | |
111 | ||
112 | get (options: OverrideCommandOptions & { | |
113 | channelName: string | |
114 | }) { | |
115 | const path = '/api/v1/video-channels/' + options.channelName | |
116 | ||
117 | return this.getRequestBody<VideoChannel>({ | |
118 | ...options, | |
119 | ||
120 | path, | |
121 | implicitToken: false, | |
122 | defaultExpectedStatus: HttpStatusCode.OK_200 | |
123 | }) | |
124 | } | |
125 | ||
126 | updateImage (options: OverrideCommandOptions & { | |
127 | fixture: string | |
128 | channelName: string | number | |
129 | type: 'avatar' | 'banner' | |
130 | }) { | |
131 | const { channelName, fixture, type } = options | |
132 | ||
133 | const path = `/api/v1/video-channels/${channelName}/${type}/pick` | |
134 | ||
135 | return this.updateImageRequest({ | |
136 | ...options, | |
137 | ||
138 | path, | |
139 | fixture, | |
140 | fieldname: type + 'file', | |
141 | ||
142 | implicitToken: true, | |
143 | defaultExpectedStatus: HttpStatusCode.OK_200 | |
144 | }) | |
145 | } | |
146 | ||
147 | deleteImage (options: OverrideCommandOptions & { | |
148 | channelName: string | number | |
149 | type: 'avatar' | 'banner' | |
150 | }) { | |
151 | const { channelName, type } = options | |
152 | ||
153 | const path = `/api/v1/video-channels/${channelName}/${type}` | |
154 | ||
155 | return this.deleteRequest({ | |
156 | ...options, | |
157 | ||
158 | path, | |
159 | implicitToken: true, | |
160 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | |
161 | }) | |
162 | } | |
4beda9e1 C |
163 | |
164 | listFollowers (options: OverrideCommandOptions & { | |
165 | channelName: string | |
166 | start?: number | |
167 | count?: number | |
168 | sort?: string | |
169 | search?: string | |
170 | }) { | |
171 | const { channelName, start, count, sort, search } = options | |
172 | const path = '/api/v1/video-channels/' + channelName + '/followers' | |
173 | ||
174 | const query = { start, count, sort, search } | |
175 | ||
176 | return this.getRequestBody<ResultList<ActorFollow>>({ | |
177 | ...options, | |
178 | ||
179 | path, | |
180 | query, | |
181 | implicitToken: true, | |
182 | defaultExpectedStatus: HttpStatusCode.OK_200 | |
183 | }) | |
184 | } | |
2a491182 | 185 | |
a3b472a1 | 186 | importVideos (options: OverrideCommandOptions & VideosImportInChannelCreate & { |
2a491182 | 187 | channelName: string |
2a491182 | 188 | }) { |
a3b472a1 | 189 | const { channelName, externalChannelUrl, videoChannelSyncId } = options |
2a491182 F |
190 | |
191 | const path = `/api/v1/video-channels/${channelName}/import-videos` | |
192 | ||
193 | return this.postBodyRequest({ | |
194 | ...options, | |
195 | ||
196 | path, | |
a3b472a1 | 197 | fields: { externalChannelUrl, videoChannelSyncId }, |
2a491182 F |
198 | implicitToken: true, |
199 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | |
200 | }) | |
201 | } | |
a5461888 | 202 | } |