1 import { pick } from '@shared/core-utils'
8 VideoChannelCreateResult,
10 } from '@shared/models'
11 import { unwrapBody } from '../requests'
12 import { AbstractCommand, OverrideCommandOptions } from '../shared'
14 export class ChannelsCommand extends AbstractCommand {
16 list (options: OverrideCommandOptions & {
22 const path = '/api/v1/video-channels'
24 return this.getRequestBody<ResultList<VideoChannel>>({
28 query: pick(options, [ 'start', 'count', 'sort', 'withStats' ]),
30 defaultExpectedStatus: HttpStatusCode.OK_200
34 listByAccount (options: OverrideCommandOptions & {
42 const { accountName, sort = 'createdAt' } = options
43 const path = '/api/v1/accounts/' + accountName + '/video-channels'
45 return this.getRequestBody<ResultList<VideoChannel>>({
49 query: { sort, ...pick(options, [ 'start', 'count', 'withStats', 'search' ]) },
51 defaultExpectedStatus: HttpStatusCode.OK_200
55 async create (options: OverrideCommandOptions & {
56 attributes: Partial<VideoChannelCreate>
58 const path = '/api/v1/video-channels/'
61 const defaultAttributes = {
62 displayName: 'my super video channel',
63 description: 'my super channel description',
64 support: 'my super channel support'
66 const attributes = { ...defaultAttributes, ...options.attributes }
68 const body = await unwrapBody<{ videoChannel: VideoChannelCreateResult }>(this.postBodyRequest({
74 defaultExpectedStatus: HttpStatusCode.OK_200
77 return body.videoChannel
80 update (options: OverrideCommandOptions & {
82 attributes: VideoChannelUpdate
84 const { channelName, attributes } = options
85 const path = '/api/v1/video-channels/' + channelName
87 return this.putBodyRequest({
93 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
97 delete (options: OverrideCommandOptions & {
100 const path = '/api/v1/video-channels/' + options.channelName
102 return this.deleteRequest({
107 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
111 get (options: OverrideCommandOptions & {
114 const path = '/api/v1/video-channels/' + options.channelName
116 return this.getRequestBody<VideoChannel>({
120 implicitToken: false,
121 defaultExpectedStatus: HttpStatusCode.OK_200
125 updateImage (options: OverrideCommandOptions & {
127 channelName: string | number
128 type: 'avatar' | 'banner'
130 const { channelName, fixture, type } = options
132 const path = `/api/v1/video-channels/${channelName}/${type}/pick`
134 return this.updateImageRequest({
139 fieldname: type + 'file',
142 defaultExpectedStatus: HttpStatusCode.OK_200
146 deleteImage (options: OverrideCommandOptions & {
147 channelName: string | number
148 type: 'avatar' | 'banner'
150 const { channelName, type } = options
152 const path = `/api/v1/video-channels/${channelName}/${type}`
154 return this.deleteRequest({
159 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
163 listFollowers (options: OverrideCommandOptions & {
170 const { channelName, start, count, sort, search } = options
171 const path = '/api/v1/video-channels/' + channelName + '/followers'
173 const query = { start, count, sort, search }
175 return this.getRequestBody<ResultList<ActorFollow>>({
181 defaultExpectedStatus: HttpStatusCode.OK_200