1 import { pick } from '@shared/core-utils'
8 VideoChannelCreateResult,
10 VideosImportInChannelCreate
11 } from '@shared/models'
12 import { unwrapBody } from '../requests'
13 import { AbstractCommand, OverrideCommandOptions } from '../shared'
15 export class ChannelsCommand extends AbstractCommand {
17 list (options: OverrideCommandOptions & {
23 const path = '/api/v1/video-channels'
25 return this.getRequestBody<ResultList<VideoChannel>>({
29 query: pick(options, [ 'start', 'count', 'sort', 'withStats' ]),
31 defaultExpectedStatus: HttpStatusCode.OK_200
35 listByAccount (options: OverrideCommandOptions & {
43 const { accountName, sort = 'createdAt' } = options
44 const path = '/api/v1/accounts/' + accountName + '/video-channels'
46 return this.getRequestBody<ResultList<VideoChannel>>({
50 query: { sort, ...pick(options, [ 'start', 'count', 'withStats', 'search' ]) },
52 defaultExpectedStatus: HttpStatusCode.OK_200
56 async create (options: OverrideCommandOptions & {
57 attributes: Partial<VideoChannelCreate>
59 const path = '/api/v1/video-channels/'
62 const defaultAttributes = {
63 displayName: 'my super video channel',
64 description: 'my super channel description',
65 support: 'my super channel support'
67 const attributes = { ...defaultAttributes, ...options.attributes }
69 const body = await unwrapBody<{ videoChannel: VideoChannelCreateResult }>(this.postBodyRequest({
75 defaultExpectedStatus: HttpStatusCode.OK_200
78 return body.videoChannel
81 update (options: OverrideCommandOptions & {
83 attributes: VideoChannelUpdate
85 const { channelName, attributes } = options
86 const path = '/api/v1/video-channels/' + channelName
88 return this.putBodyRequest({
94 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
98 delete (options: OverrideCommandOptions & {
101 const path = '/api/v1/video-channels/' + options.channelName
103 return this.deleteRequest({
108 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
112 get (options: OverrideCommandOptions & {
115 const path = '/api/v1/video-channels/' + options.channelName
117 return this.getRequestBody<VideoChannel>({
121 implicitToken: false,
122 defaultExpectedStatus: HttpStatusCode.OK_200
126 updateImage (options: OverrideCommandOptions & {
128 channelName: string | number
129 type: 'avatar' | 'banner'
131 const { channelName, fixture, type } = options
133 const path = `/api/v1/video-channels/${channelName}/${type}/pick`
135 return this.updateImageRequest({
140 fieldname: type + 'file',
143 defaultExpectedStatus: HttpStatusCode.OK_200
147 deleteImage (options: OverrideCommandOptions & {
148 channelName: string | number
149 type: 'avatar' | 'banner'
151 const { channelName, type } = options
153 const path = `/api/v1/video-channels/${channelName}/${type}`
155 return this.deleteRequest({
160 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
164 listFollowers (options: OverrideCommandOptions & {
171 const { channelName, start, count, sort, search } = options
172 const path = '/api/v1/video-channels/' + channelName + '/followers'
174 const query = { start, count, sort, search }
176 return this.getRequestBody<ResultList<ActorFollow>>({
182 defaultExpectedStatus: HttpStatusCode.OK_200
186 importVideos (options: OverrideCommandOptions & VideosImportInChannelCreate & {
189 const { channelName, externalChannelUrl, videoChannelSyncId } = options
191 const path = `/api/v1/video-channels/${channelName}/import-videos`
193 return this.postBodyRequest({
197 fields: { externalChannelUrl, videoChannelSyncId },
199 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204