diff options
Diffstat (limited to 'shared/utils/videos/video-channels.ts')
-rw-r--r-- | shared/utils/videos/video-channels.ts | 134 |
1 files changed, 0 insertions, 134 deletions
diff --git a/shared/utils/videos/video-channels.ts b/shared/utils/videos/video-channels.ts deleted file mode 100644 index 93a257bf9..000000000 --- a/shared/utils/videos/video-channels.ts +++ /dev/null | |||
@@ -1,134 +0,0 @@ | |||
1 | import * as request from 'supertest' | ||
2 | import { VideoChannelCreate, VideoChannelUpdate } from '../../models/videos' | ||
3 | import { updateAvatarRequest } from '../requests/requests' | ||
4 | import { getMyUserInformation, ServerInfo } from '..' | ||
5 | import { User } from '../..' | ||
6 | |||
7 | function 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 | |||
22 | function 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 | |||
32 | function 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 | |||
56 | function 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 | |||
78 | function 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 | |||
88 | function 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 | |||
98 | function 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 | |||
110 | function 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 | |||
125 | export { | ||
126 | updateVideoChannelAvatar, | ||
127 | getVideoChannelsList, | ||
128 | getAccountVideoChannelsList, | ||
129 | addVideoChannel, | ||
130 | updateVideoChannel, | ||
131 | deleteVideoChannel, | ||
132 | getVideoChannel, | ||
133 | setDefaultVideoChannel | ||
134 | } | ||