1 import * as request from 'supertest'
2 import { VideoChannelUpdate } from '../../models/videos/channel/video-channel-update.model'
3 import { VideoChannelCreate } from '../../models/videos/channel/video-channel-create.model'
4 import { makeGetRequest, updateAvatarRequest } from '../requests/requests'
5 import { ServerInfo } from '../server/servers'
6 import { User } from '../../models/users/user.model'
7 import { getMyUserInformation } from '../users/users'
9 function getVideoChannelsList (url: string, start: number, count: number, sort?: string) {
10 const path = '/api/v1/video-channels'
12 const req = request(url)
14 .query({ start: start })
15 .query({ count: count })
17 if (sort) req.query({ sort })
19 return req.set('Accept', 'application/json')
21 .expect('Content-Type', /json/)
24 function getAccountVideoChannelsList (parameters: {
30 specialStatus?: number
32 const { url, accountName, start, count, sort = 'createdAt', specialStatus = 200 } = parameters
34 const path = '/api/v1/accounts/' + accountName + '/video-channels'
36 return makeGetRequest({
44 statusCodeExpected: specialStatus
48 function addVideoChannel (
51 videoChannelAttributesArg: VideoChannelCreate,
54 const path = '/api/v1/video-channels/'
58 displayName: 'my super video channel',
59 description: 'my super channel description',
60 support: 'my super channel support'
62 attributes = Object.assign(attributes, videoChannelAttributesArg)
67 .set('Accept', 'application/json')
68 .set('Authorization', 'Bearer ' + token)
69 .expect(expectedStatus)
72 function updateVideoChannel (
76 attributes: VideoChannelUpdate,
80 const path = '/api/v1/video-channels/' + channelName
82 if (attributes.displayName) body.displayName = attributes.displayName
83 if (attributes.description) body.description = attributes.description
84 if (attributes.support) body.support = attributes.support
85 if (attributes.bulkVideosSupportUpdate) body.bulkVideosSupportUpdate = attributes.bulkVideosSupportUpdate
90 .set('Accept', 'application/json')
91 .set('Authorization', 'Bearer ' + token)
92 .expect(expectedStatus)
95 function deleteVideoChannel (url: string, token: string, channelName: string, expectedStatus = 204) {
96 const path = '/api/v1/video-channels/' + channelName
100 .set('Accept', 'application/json')
101 .set('Authorization', 'Bearer ' + token)
102 .expect(expectedStatus)
105 function getVideoChannel (url: string, channelName: string) {
106 const path = '/api/v1/video-channels/' + channelName
110 .set('Accept', 'application/json')
112 .expect('Content-Type', /json/)
115 function updateVideoChannelAvatar (options: {
119 videoChannelName: string | number
122 const path = '/api/v1/video-channels/' + options.videoChannelName + '/avatar/pick'
124 return updateAvatarRequest(Object.assign(options, { path }))
127 function setDefaultVideoChannel (servers: ServerInfo[]) {
128 const tasks: Promise<any>[] = []
130 for (const server of servers) {
131 const p = getMyUserInformation(server.url, server.accessToken)
132 .then(res => server.videoChannel = (res.body as User).videoChannels[0])
137 return Promise.all(tasks)
140 // ---------------------------------------------------------------------------
143 updateVideoChannelAvatar,
144 getVideoChannelsList,
145 getAccountVideoChannelsList,
150 setDefaultVideoChannel