]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/extra-utils/videos/video-channels.ts
Add audio support in upload
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / videos / video-channels.ts
CommitLineData
5f04dd2f 1import * as request from 'supertest'
d4681c00 2import { VideoChannelCreate, VideoChannelUpdate } from '../../models/videos'
d175a6f7 3import { updateAvatarRequest } from '../requests/requests'
df0b219d
C
4import { getMyUserInformation, ServerInfo } from '..'
5import { User } from '../..'
5f04dd2f
C
6
7function getVideoChannelsList (url: string, start: number, count: number, sort?: string) {
48dce1c9 8 const path = '/api/v1/video-channels'
5f04dd2f
C
9
10 const req = request(url)
11 .get(path)
12 .query({ start: start })
13 .query({ count: count })
14
15 if (sort) req.query({ sort })
16
17 return req.set('Accept', 'application/json')
18 .expect(200)
19 .expect('Content-Type', /json/)
20}
21
ad9e39fb
C
22function getAccountVideoChannelsList (url: string, accountName: string, specialStatus = 200) {
23 const path = '/api/v1/accounts/' + accountName + '/video-channels'
5f04dd2f
C
24
25 return request(url)
26 .get(path)
27 .set('Accept', 'application/json')
11ba2ab3 28 .expect(specialStatus)
5f04dd2f
C
29 .expect('Content-Type', /json/)
30}
31
48dce1c9
C
32function addVideoChannel (
33 url: string,
34 token: string,
08c1efbe 35 videoChannelAttributesArg: VideoChannelCreate,
48dce1c9
C
36 expectedStatus = 200
37) {
cc918ac3 38 const path = '/api/v1/video-channels/'
5f04dd2f
C
39
40 // Default attributes
41 let attributes = {
08c1efbe 42 displayName: 'my super video channel',
2422c46b
C
43 description: 'my super channel description',
44 support: 'my super channel support'
5f04dd2f
C
45 }
46 attributes = Object.assign(attributes, videoChannelAttributesArg)
47
48 return request(url)
49 .post(path)
50 .send(attributes)
51 .set('Accept', 'application/json')
52 .set('Authorization', 'Bearer ' + token)
53 .expect(expectedStatus)
54}
55
48dce1c9
C
56function updateVideoChannel (
57 url: string,
58 token: string,
f5b0af50 59 channelName: string,
08c1efbe 60 attributes: VideoChannelUpdate,
48dce1c9
C
61 expectedStatus = 204
62) {
5f04dd2f 63 const body = {}
f5b0af50 64 const path = '/api/v1/video-channels/' + channelName
5f04dd2f 65
08c1efbe 66 if (attributes.displayName) body['displayName'] = attributes.displayName
5f04dd2f 67 if (attributes.description) body['description'] = attributes.description
2422c46b 68 if (attributes.support) body['support'] = attributes.support
5f04dd2f
C
69
70 return request(url)
71 .put(path)
72 .send(body)
73 .set('Accept', 'application/json')
74 .set('Authorization', 'Bearer ' + token)
75 .expect(expectedStatus)
76}
77
f5b0af50
C
78function deleteVideoChannel (url: string, token: string, channelName: string, expectedStatus = 204) {
79 const path = '/api/v1/video-channels/' + channelName
5f04dd2f
C
80
81 return request(url)
48dce1c9 82 .delete(path)
5f04dd2f
C
83 .set('Accept', 'application/json')
84 .set('Authorization', 'Bearer ' + token)
85 .expect(expectedStatus)
86}
87
f5b0af50
C
88function getVideoChannel (url: string, channelName: string) {
89 const path = '/api/v1/video-channels/' + channelName
5f04dd2f
C
90
91 return request(url)
92 .get(path)
93 .set('Accept', 'application/json')
94 .expect(200)
95 .expect('Content-Type', /json/)
96}
97
4bbfc6c6
C
98function updateVideoChannelAvatar (options: {
99 url: string,
100 accessToken: string,
101 fixture: string,
8a19bee1 102 videoChannelName: string | number
4bbfc6c6
C
103}) {
104
8a19bee1 105 const path = '/api/v1/video-channels/' + options.videoChannelName + '/avatar/pick'
4bbfc6c6
C
106
107 return updateAvatarRequest(Object.assign(options, { path }))
108}
109
df0b219d
C
110function setDefaultVideoChannel (servers: ServerInfo[]) {
111 const tasks: Promise<any>[] = []
112
113 for (const server of servers) {
114 const p = getMyUserInformation(server.url, server.accessToken)
115 .then(res => server.videoChannel = (res.body as User).videoChannels[0])
116
117 tasks.push(p)
118 }
119
120 return Promise.all(tasks)
121}
122
5f04dd2f
C
123// ---------------------------------------------------------------------------
124
125export {
4bbfc6c6 126 updateVideoChannelAvatar,
5f04dd2f 127 getVideoChannelsList,
975e6e0e 128 getAccountVideoChannelsList,
5f04dd2f
C
129 addVideoChannel,
130 updateVideoChannel,
131 deleteVideoChannel,
df0b219d
C
132 getVideoChannel,
133 setDefaultVideoChannel
5f04dd2f 134}