aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/videos/video-channels.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-04-15 15:26:15 +0200
committerChocobozzz <me@florianbigard.com>2019-04-24 16:25:52 +0200
commit94565d52bb2883e09f16d1363170ac9c0dccb7a1 (patch)
tree3dcd20cd7b5a5cca80bce32b655cdbfaddf7aa59 /shared/extra-utils/videos/video-channels.ts
parent4ee7a4c9ac9280cda930a281c2d5a9a4c409cc14 (diff)
downloadPeerTube-94565d52bb2883e09f16d1363170ac9c0dccb7a1.tar.gz
PeerTube-94565d52bb2883e09f16d1363170ac9c0dccb7a1.tar.zst
PeerTube-94565d52bb2883e09f16d1363170ac9c0dccb7a1.zip
Shared utils -> extra-utils
Because they need dev dependencies
Diffstat (limited to 'shared/extra-utils/videos/video-channels.ts')
-rw-r--r--shared/extra-utils/videos/video-channels.ts134
1 files changed, 134 insertions, 0 deletions
diff --git a/shared/extra-utils/videos/video-channels.ts b/shared/extra-utils/videos/video-channels.ts
new file mode 100644
index 000000000..93a257bf9
--- /dev/null
+++ b/shared/extra-utils/videos/video-channels.ts
@@ -0,0 +1,134 @@
1import * as request from 'supertest'
2import { VideoChannelCreate, VideoChannelUpdate } from '../../models/videos'
3import { updateAvatarRequest } from '../requests/requests'
4import { getMyUserInformation, ServerInfo } from '..'
5import { User } from '../..'
6
7function getVideoChannelsList (url: string, start: number, count: number, sort?: string) {
8 const path = '/api/v1/video-channels'
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
22function getAccountVideoChannelsList (url: string, accountName: string, specialStatus = 200) {
23 const path = '/api/v1/accounts/' + accountName + '/video-channels'
24
25 return request(url)
26 .get(path)
27 .set('Accept', 'application/json')
28 .expect(specialStatus)
29 .expect('Content-Type', /json/)
30}
31
32function addVideoChannel (
33 url: string,
34 token: string,
35 videoChannelAttributesArg: VideoChannelCreate,
36 expectedStatus = 200
37) {
38 const path = '/api/v1/video-channels/'
39
40 // Default attributes
41 let attributes = {
42 displayName: 'my super video channel',
43 description: 'my super channel description',
44 support: 'my super channel support'
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
56function updateVideoChannel (
57 url: string,
58 token: string,
59 channelName: string,
60 attributes: VideoChannelUpdate,
61 expectedStatus = 204
62) {
63 const body = {}
64 const path = '/api/v1/video-channels/' + channelName
65
66 if (attributes.displayName) body['displayName'] = attributes.displayName
67 if (attributes.description) body['description'] = attributes.description
68 if (attributes.support) body['support'] = attributes.support
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
78function deleteVideoChannel (url: string, token: string, channelName: string, expectedStatus = 204) {
79 const path = '/api/v1/video-channels/' + channelName
80
81 return request(url)
82 .delete(path)
83 .set('Accept', 'application/json')
84 .set('Authorization', 'Bearer ' + token)
85 .expect(expectedStatus)
86}
87
88function getVideoChannel (url: string, channelName: string) {
89 const path = '/api/v1/video-channels/' + channelName
90
91 return request(url)
92 .get(path)
93 .set('Accept', 'application/json')
94 .expect(200)
95 .expect('Content-Type', /json/)
96}
97
98function updateVideoChannelAvatar (options: {
99 url: string,
100 accessToken: string,
101 fixture: string,
102 videoChannelName: string | number
103}) {
104
105 const path = '/api/v1/video-channels/' + options.videoChannelName + '/avatar/pick'
106
107 return updateAvatarRequest(Object.assign(options, { path }))
108}
109
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
123// ---------------------------------------------------------------------------
124
125export {
126 updateVideoChannelAvatar,
127 getVideoChannelsList,
128 getAccountVideoChannelsList,
129 addVideoChannel,
130 updateVideoChannel,
131 deleteVideoChannel,
132 getVideoChannel,
133 setDefaultVideoChannel
134}