1 import { pick } from 'lodash'
2 import { ResultList, VideoChannel, VideoChannelCreateResult } from '@shared/models'
3 import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
4 import { VideoChannelCreate } from '../../models/videos/channel/video-channel-create.model'
5 import { VideoChannelUpdate } from '../../models/videos/channel/video-channel-update.model'
6 import { unwrapBody } from '../requests'
7 import { AbstractCommand, OverrideCommandOptions } from '../shared'
9 export class ChannelsCommand extends AbstractCommand {
11 list (options: OverrideCommandOptions & {
17 const path = '/api/v1/video-channels'
19 return this.getRequestBody<ResultList<VideoChannel>>({
23 query: pick(options, [ 'start', 'count', 'sort', 'withStats' ]),
25 defaultExpectedStatus: HttpStatusCode.OK_200
29 listByAccount (options: OverrideCommandOptions & {
37 const { accountName, sort = 'createdAt' } = options
38 const path = '/api/v1/accounts/' + accountName + '/video-channels'
40 return this.getRequestBody<ResultList<VideoChannel>>({
44 query: { sort, ...pick(options, [ 'start', 'count', 'withStats', 'search' ]) },
46 defaultExpectedStatus: HttpStatusCode.OK_200
50 async create (options: OverrideCommandOptions & {
51 attributes: VideoChannelCreate
53 const path = '/api/v1/video-channels/'
56 const defaultAttributes = {
57 displayName: 'my super video channel',
58 description: 'my super channel description',
59 support: 'my super channel support'
61 const attributes = { ...defaultAttributes, ...options.attributes }
63 const body = await unwrapBody<{ videoChannel: VideoChannelCreateResult }>(this.postBodyRequest({
69 defaultExpectedStatus: HttpStatusCode.OK_200
72 return body.videoChannel
75 update (options: OverrideCommandOptions & {
77 attributes: VideoChannelUpdate
79 const { channelName, attributes } = options
80 const path = '/api/v1/video-channels/' + channelName
82 return this.putBodyRequest({
88 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
92 delete (options: OverrideCommandOptions & {
95 const path = '/api/v1/video-channels/' + options.channelName
97 return this.deleteRequest({
102 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
106 get (options: OverrideCommandOptions & {
109 const path = '/api/v1/video-channels/' + options.channelName
111 return this.getRequestBody<VideoChannel>({
115 implicitToken: false,
116 defaultExpectedStatus: HttpStatusCode.OK_200
120 updateImage (options: OverrideCommandOptions & {
122 channelName: string | number
123 type: 'avatar' | 'banner'
125 const { channelName, fixture, type } = options
127 const path = `/api/v1/video-channels/${channelName}/${type}/pick`
129 return this.updateImageRequest({
134 fieldname: type + 'file',
137 defaultExpectedStatus: HttpStatusCode.OK_200
141 deleteImage (options: OverrideCommandOptions & {
142 channelName: string | number
143 type: 'avatar' | 'banner'
145 const { channelName, type } = options
147 const path = `/api/v1/video-channels/${channelName}/${type}`
149 return this.deleteRequest({
154 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204