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
36 const { url, accountName, start, count, sort = 'createdAt', specialStatus = 200, withStats = false } = parameters
38 const path = '/api/v1/accounts/' + accountName + '/video-channels'
40 return makeGetRequest({
49 statusCodeExpected: specialStatus
53 function addVideoChannel (
56 videoChannelAttributesArg: VideoChannelCreate,
59 const path = '/api/v1/video-channels/'
63 displayName: 'my super video channel',
64 description: 'my super channel description',
65 support: 'my super channel support'
67 attributes = Object.assign(attributes, videoChannelAttributesArg)
72 .set('Accept', 'application/json')
73 .set('Authorization', 'Bearer ' + token)
74 .expect(expectedStatus)
77 function updateVideoChannel (
81 attributes: VideoChannelUpdate,
85 const path = '/api/v1/video-channels/' + channelName
87 if (attributes.displayName) body.displayName = attributes.displayName
88 if (attributes.description) body.description = attributes.description
89 if (attributes.support) body.support = attributes.support
90 if (attributes.bulkVideosSupportUpdate) body.bulkVideosSupportUpdate = attributes.bulkVideosSupportUpdate
95 .set('Accept', 'application/json')
96 .set('Authorization', 'Bearer ' + token)
97 .expect(expectedStatus)
100 function deleteVideoChannel (url: string, token: string, channelName: string, expectedStatus = 204) {
101 const path = '/api/v1/video-channels/' + channelName
105 .set('Accept', 'application/json')
106 .set('Authorization', 'Bearer ' + token)
107 .expect(expectedStatus)
110 function getVideoChannel (url: string, channelName: string) {
111 const path = '/api/v1/video-channels/' + channelName
115 .set('Accept', 'application/json')
117 .expect('Content-Type', /json/)
120 function updateVideoChannelAvatar (options: {
124 videoChannelName: string | number
127 const path = '/api/v1/video-channels/' + options.videoChannelName + '/avatar/pick'
129 return updateAvatarRequest(Object.assign(options, { path }))
132 function setDefaultVideoChannel (servers: ServerInfo[]) {
133 const tasks: Promise<any>[] = []
135 for (const server of servers) {
136 const p = getMyUserInformation(server.url, server.accessToken)
137 .then(res => { server.videoChannel = (res.body as User).videoChannels[0] })
142 return Promise.all(tasks)
145 // ---------------------------------------------------------------------------
148 updateVideoChannelAvatar,
149 getVideoChannelsList,
150 getAccountVideoChannelsList,
155 setDefaultVideoChannel