1 import { pick } from 'lodash'
2 import { HttpStatusCode, ResultList, VideoChannel, VideoChannelCreateResult } from '@shared/models'
3 import { VideoChannelCreate } from '../../models/videos/channel/video-channel-create.model'
4 import { VideoChannelUpdate } from '../../models/videos/channel/video-channel-update.model'
5 import { unwrapBody } from '../requests'
6 import { AbstractCommand, OverrideCommandOptions } from '../shared'
8 export class ChannelsCommand extends AbstractCommand {
10 list (options: OverrideCommandOptions & {
16 const path = '/api/v1/video-channels'
18 return this.getRequestBody<ResultList<VideoChannel>>({
22 query: pick(options, [ 'start', 'count', 'sort', 'withStats' ]),
24 defaultExpectedStatus: HttpStatusCode.OK_200
28 listByAccount (options: OverrideCommandOptions & {
36 const { accountName, sort = 'createdAt' } = options
37 const path = '/api/v1/accounts/' + accountName + '/video-channels'
39 return this.getRequestBody<ResultList<VideoChannel>>({
43 query: { sort, ...pick(options, [ 'start', 'count', 'withStats', 'search' ]) },
45 defaultExpectedStatus: HttpStatusCode.OK_200
49 async create (options: OverrideCommandOptions & {
50 attributes: VideoChannelCreate
52 const path = '/api/v1/video-channels/'
55 const defaultAttributes = {
56 displayName: 'my super video channel',
57 description: 'my super channel description',
58 support: 'my super channel support'
60 const attributes = { ...defaultAttributes, ...options.attributes }
62 const body = await unwrapBody<{ videoChannel: VideoChannelCreateResult }>(this.postBodyRequest({
68 defaultExpectedStatus: HttpStatusCode.OK_200
71 return body.videoChannel
74 update (options: OverrideCommandOptions & {
76 attributes: VideoChannelUpdate
78 const { channelName, attributes } = options
79 const path = '/api/v1/video-channels/' + channelName
81 return this.putBodyRequest({
87 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
91 delete (options: OverrideCommandOptions & {
94 const path = '/api/v1/video-channels/' + options.channelName
96 return this.deleteRequest({
101 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
105 get (options: OverrideCommandOptions & {
108 const path = '/api/v1/video-channels/' + options.channelName
110 return this.getRequestBody<VideoChannel>({
114 implicitToken: false,
115 defaultExpectedStatus: HttpStatusCode.OK_200
119 updateImage (options: OverrideCommandOptions & {
121 channelName: string | number
122 type: 'avatar' | 'banner'
124 const { channelName, fixture, type } = options
126 const path = `/api/v1/video-channels/${channelName}/${type}/pick`
128 return this.updateImageRequest({
133 fieldname: type + 'file',
136 defaultExpectedStatus: HttpStatusCode.OK_200
140 deleteImage (options: OverrideCommandOptions & {
141 channelName: string | number
142 type: 'avatar' | 'banner'
144 const { channelName, type } = options
146 const path = `/api/v1/video-channels/${channelName}/${type}`
148 return this.deleteRequest({
153 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204