1 import * as request from 'supertest'
2 import { VideoChannelCreate, VideoChannelUpdate } from '../../models/videos'
3 import { makeGetRequest, updateAvatarRequest } from '../requests/requests'
4 import { getMyUserInformation, ServerInfo } from '..'
5 import { User } from '../..'
7 function getVideoChannelsList (url: string, start: number, count: number, sort?: string) {
8 const path = '/api/v1/video-channels'
10 const req = request(url)
12 .query({ start: start })
13 .query({ count: count })
15 if (sort) req.query({ sort })
17 return req.set('Accept', 'application/json')
19 .expect('Content-Type', /json/)
22 function getAccountVideoChannelsList (parameters: {
28 specialStatus?: number
30 const { url, accountName, start, count, sort = 'createdAt', specialStatus = 200 } = parameters
32 const path = '/api/v1/accounts/' + accountName + '/video-channels'
34 return makeGetRequest({
42 statusCodeExpected: specialStatus
46 function addVideoChannel (
49 videoChannelAttributesArg: VideoChannelCreate,
52 const path = '/api/v1/video-channels/'
56 displayName: 'my super video channel',
57 description: 'my super channel description',
58 support: 'my super channel support'
60 attributes = Object.assign(attributes, videoChannelAttributesArg)
65 .set('Accept', 'application/json')
66 .set('Authorization', 'Bearer ' + token)
67 .expect(expectedStatus)
70 function updateVideoChannel (
74 attributes: VideoChannelUpdate,
78 const path = '/api/v1/video-channels/' + channelName
80 if (attributes.displayName) body.displayName = attributes.displayName
81 if (attributes.description) body.description = attributes.description
82 if (attributes.support) body.support = attributes.support
83 if (attributes.bulkVideosSupportUpdate) body.bulkVideosSupportUpdate = attributes.bulkVideosSupportUpdate
88 .set('Accept', 'application/json')
89 .set('Authorization', 'Bearer ' + token)
90 .expect(expectedStatus)
93 function deleteVideoChannel (url: string, token: string, channelName: string, expectedStatus = 204) {
94 const path = '/api/v1/video-channels/' + channelName
98 .set('Accept', 'application/json')
99 .set('Authorization', 'Bearer ' + token)
100 .expect(expectedStatus)
103 function getVideoChannel (url: string, channelName: string) {
104 const path = '/api/v1/video-channels/' + channelName
108 .set('Accept', 'application/json')
110 .expect('Content-Type', /json/)
113 function updateVideoChannelAvatar (options: {
117 videoChannelName: string | number
120 const path = '/api/v1/video-channels/' + options.videoChannelName + '/avatar/pick'
122 return updateAvatarRequest(Object.assign(options, { path }))
125 function setDefaultVideoChannel (servers: ServerInfo[]) {
126 const tasks: Promise<any>[] = []
128 for (const server of servers) {
129 const p = getMyUserInformation(server.url, server.accessToken)
130 .then(res => server.videoChannel = (res.body as User).videoChannels[0])
135 return Promise.all(tasks)
138 // ---------------------------------------------------------------------------
141 updateVideoChannelAvatar,
142 getVideoChannelsList,
143 getAccountVideoChannelsList,
148 setDefaultVideoChannel