1 /* eslint-disable @typescript-eslint/no-floating-promises */
3 import * as request from 'supertest'
4 import { VideoChannelUpdate } from '../../models/videos/channel/video-channel-update.model'
5 import { VideoChannelCreate } from '../../models/videos/channel/video-channel-create.model'
6 import { makeGetRequest, updateAvatarRequest } from '../requests/requests'
7 import { ServerInfo } from '../server/servers'
8 import { User } from '../../models/users/user.model'
9 import { getMyUserInformation } from '../users/users'
11 function getVideoChannelsList (url: string, start: number, count: number, sort?: string, withStats?: boolean) {
12 const path = '/api/v1/video-channels'
14 const req = request(url)
16 .query({ start: start })
17 .query({ count: count })
19 if (sort) req.query({ sort })
20 if (withStats) req.query({ withStats })
22 return req.set('Accept', 'application/json')
24 .expect('Content-Type', /json/)
27 function getAccountVideoChannelsList (parameters: {
33 specialStatus?: number
37 const { url, accountName, start, count, sort = 'createdAt', specialStatus = 200, withStats = false, search } = parameters
39 const path = '/api/v1/accounts/' + accountName + '/video-channels'
41 return makeGetRequest({
51 statusCodeExpected: specialStatus
55 function addVideoChannel (
58 videoChannelAttributesArg: VideoChannelCreate,
61 const path = '/api/v1/video-channels/'
65 displayName: 'my super video channel',
66 description: 'my super channel description',
67 support: 'my super channel support'
69 attributes = Object.assign(attributes, videoChannelAttributesArg)
74 .set('Accept', 'application/json')
75 .set('Authorization', 'Bearer ' + token)
76 .expect(expectedStatus)
79 function updateVideoChannel (
83 attributes: VideoChannelUpdate,
87 const path = '/api/v1/video-channels/' + channelName
89 if (attributes.displayName) body.displayName = attributes.displayName
90 if (attributes.description) body.description = attributes.description
91 if (attributes.support) body.support = attributes.support
92 if (attributes.bulkVideosSupportUpdate) body.bulkVideosSupportUpdate = attributes.bulkVideosSupportUpdate
97 .set('Accept', 'application/json')
98 .set('Authorization', 'Bearer ' + token)
99 .expect(expectedStatus)
102 function deleteVideoChannel (url: string, token: string, channelName: string, expectedStatus = 204) {
103 const path = '/api/v1/video-channels/' + channelName
107 .set('Accept', 'application/json')
108 .set('Authorization', 'Bearer ' + token)
109 .expect(expectedStatus)
112 function getVideoChannel (url: string, channelName: string) {
113 const path = '/api/v1/video-channels/' + channelName
117 .set('Accept', 'application/json')
119 .expect('Content-Type', /json/)
122 function updateVideoChannelAvatar (options: {
126 videoChannelName: string | number
129 const path = '/api/v1/video-channels/' + options.videoChannelName + '/avatar/pick'
131 return updateAvatarRequest(Object.assign(options, { path }))
134 function setDefaultVideoChannel (servers: ServerInfo[]) {
135 const tasks: Promise<any>[] = []
137 for (const server of servers) {
138 const p = getMyUserInformation(server.url, server.accessToken)
139 .then(res => { server.videoChannel = (res.body as User).videoChannels[0] })
144 return Promise.all(tasks)
147 // ---------------------------------------------------------------------------
150 updateVideoChannelAvatar,
151 getVideoChannelsList,
152 getAccountVideoChannelsList,
157 setDefaultVideoChannel