aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/videos/videos.ts
diff options
context:
space:
mode:
Diffstat (limited to 'shared/extra-utils/videos/videos.ts')
-rw-r--r--shared/extra-utils/videos/videos.ts49
1 files changed, 28 insertions, 21 deletions
diff --git a/shared/extra-utils/videos/videos.ts b/shared/extra-utils/videos/videos.ts
index 2b8c55acb..a4b9d688e 100644
--- a/shared/extra-utils/videos/videos.ts
+++ b/shared/extra-utils/videos/videos.ts
@@ -1,5 +1,6 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */
2 2
3import { HttpStatusCode } from '@shared/core-utils'
3import { expect } from 'chai' 4import { expect } from 'chai'
4import { pathExists, readdir, readFile } from 'fs-extra' 5import { pathExists, readdir, readFile } from 'fs-extra'
5import * as parseTorrent from 'parse-torrent' 6import * as parseTorrent from 'parse-torrent'
@@ -46,7 +47,7 @@ function getVideoCategories (url: string) {
46 return makeGetRequest({ 47 return makeGetRequest({
47 url, 48 url,
48 path, 49 path,
49 statusCodeExpected: 200 50 statusCodeExpected: HttpStatusCode.OK_200
50 }) 51 })
51} 52}
52 53
@@ -56,7 +57,7 @@ function getVideoLicences (url: string) {
56 return makeGetRequest({ 57 return makeGetRequest({
57 url, 58 url,
58 path, 59 path,
59 statusCodeExpected: 200 60 statusCodeExpected: HttpStatusCode.OK_200
60 }) 61 })
61} 62}
62 63
@@ -66,7 +67,7 @@ function getVideoLanguages (url: string) {
66 return makeGetRequest({ 67 return makeGetRequest({
67 url, 68 url,
68 path, 69 path,
69 statusCodeExpected: 200 70 statusCodeExpected: HttpStatusCode.OK_200
70 }) 71 })
71} 72}
72 73
@@ -76,11 +77,11 @@ function getVideoPrivacies (url: string) {
76 return makeGetRequest({ 77 return makeGetRequest({
77 url, 78 url,
78 path, 79 path,
79 statusCodeExpected: 200 80 statusCodeExpected: HttpStatusCode.OK_200
80 }) 81 })
81} 82}
82 83
83function getVideo (url: string, id: number | string, expectedStatus = 200) { 84function getVideo (url: string, id: number | string, expectedStatus = HttpStatusCode.OK_200) {
84 const path = '/api/v1/videos/' + id 85 const path = '/api/v1/videos/' + id
85 86
86 return request(url) 87 return request(url)
@@ -99,11 +100,11 @@ function getVideoFileMetadataUrl (url: string) {
99 return request(url) 100 return request(url)
100 .get('/') 101 .get('/')
101 .set('Accept', 'application/json') 102 .set('Accept', 'application/json')
102 .expect(200) 103 .expect(HttpStatusCode.OK_200)
103 .expect('Content-Type', /json/) 104 .expect('Content-Type', /json/)
104} 105}
105 106
106function viewVideo (url: string, id: number | string, expectedStatus = 204, xForwardedFor?: string) { 107function viewVideo (url: string, id: number | string, expectedStatus = HttpStatusCode.NO_CONTENT_204, xForwardedFor?: string) {
107 const path = '/api/v1/videos/' + id + '/views' 108 const path = '/api/v1/videos/' + id + '/views'
108 109
109 const req = request(url) 110 const req = request(url)
@@ -117,7 +118,7 @@ function viewVideo (url: string, id: number | string, expectedStatus = 204, xFor
117 return req.expect(expectedStatus) 118 return req.expect(expectedStatus)
118} 119}
119 120
120function getVideoWithToken (url: string, token: string, id: number | string, expectedStatus = 200) { 121function getVideoWithToken (url: string, token: string, id: number | string, expectedStatus = HttpStatusCode.OK_200) {
121 const path = '/api/v1/videos/' + id 122 const path = '/api/v1/videos/' + id
122 123
123 return request(url) 124 return request(url)
@@ -131,7 +132,7 @@ function getVideoDescription (url: string, descriptionPath: string) {
131 return request(url) 132 return request(url)
132 .get(descriptionPath) 133 .get(descriptionPath)
133 .set('Accept', 'application/json') 134 .set('Accept', 'application/json')
134 .expect(200) 135 .expect(HttpStatusCode.OK_200)
135 .expect('Content-Type', /json/) 136 .expect('Content-Type', /json/)
136} 137}
137 138
@@ -142,7 +143,7 @@ function getVideosList (url: string) {
142 .get(path) 143 .get(path)
143 .query({ sort: 'name' }) 144 .query({ sort: 'name' })
144 .set('Accept', 'application/json') 145 .set('Accept', 'application/json')
145 .expect(200) 146 .expect(HttpStatusCode.OK_200)
146 .expect('Content-Type', /json/) 147 .expect('Content-Type', /json/)
147} 148}
148 149
@@ -182,7 +183,7 @@ function getMyVideos (url: string, accessToken: string, start: number, count: nu
182 183
183 return req.set('Accept', 'application/json') 184 return req.set('Accept', 'application/json')
184 .set('Authorization', 'Bearer ' + accessToken) 185 .set('Authorization', 'Bearer ' + accessToken)
185 .expect(200) 186 .expect(HttpStatusCode.OK_200)
186 .expect('Content-Type', /json/) 187 .expect('Content-Type', /json/)
187} 188}
188 189
@@ -206,7 +207,7 @@ function getAccountVideos (
206 sort 207 sort
207 }), 208 }),
208 token: accessToken, 209 token: accessToken,
209 statusCodeExpected: 200 210 statusCodeExpected: HttpStatusCode.OK_200
210 }) 211 })
211} 212}
212 213
@@ -230,7 +231,7 @@ function getVideoChannelVideos (
230 sort 231 sort
231 }), 232 }),
232 token: accessToken, 233 token: accessToken,
233 statusCodeExpected: 200 234 statusCodeExpected: HttpStatusCode.OK_200
234 }) 235 })
235} 236}
236 237
@@ -252,7 +253,7 @@ function getPlaylistVideos (
252 count 253 count
253 }), 254 }),
254 token: accessToken, 255 token: accessToken,
255 statusCodeExpected: 200 256 statusCodeExpected: HttpStatusCode.OK_200
256 }) 257 })
257} 258}
258 259
@@ -268,7 +269,7 @@ function getVideosListPagination (url: string, start: number, count: number, sor
268 if (skipCount) req.query({ skipCount }) 269 if (skipCount) req.query({ skipCount })
269 270
270 return req.set('Accept', 'application/json') 271 return req.set('Accept', 'application/json')
271 .expect(200) 272 .expect(HttpStatusCode.OK_200)
272 .expect('Content-Type', /json/) 273 .expect('Content-Type', /json/)
273} 274}
274 275
@@ -279,7 +280,7 @@ function getVideosListSort (url: string, sort: string) {
279 .get(path) 280 .get(path)
280 .query({ sort: sort }) 281 .query({ sort: sort })
281 .set('Accept', 'application/json') 282 .set('Accept', 'application/json')
282 .expect(200) 283 .expect(HttpStatusCode.OK_200)
283 .expect('Content-Type', /json/) 284 .expect('Content-Type', /json/)
284} 285}
285 286
@@ -290,11 +291,11 @@ function getVideosWithFilters (url: string, query: { tagsAllOf: string[], catego
290 .get(path) 291 .get(path)
291 .query(query) 292 .query(query)
292 .set('Accept', 'application/json') 293 .set('Accept', 'application/json')
293 .expect(200) 294 .expect(HttpStatusCode.OK_200)
294 .expect('Content-Type', /json/) 295 .expect('Content-Type', /json/)
295} 296}
296 297
297function removeVideo (url: string, token: string, id: number | string, expectedStatus = 204) { 298function removeVideo (url: string, token: string, id: number | string, expectedStatus = HttpStatusCode.NO_CONTENT_204) {
298 const path = '/api/v1/videos' 299 const path = '/api/v1/videos'
299 300
300 return request(url) 301 return request(url)
@@ -339,7 +340,7 @@ async function checkVideoFilesWereRemoved (
339 } 340 }
340} 341}
341 342
342async function uploadVideo (url: string, accessToken: string, videoAttributesArg: VideoAttributes, specialStatus = 200) { 343async function uploadVideo (url: string, accessToken: string, videoAttributesArg: VideoAttributes, specialStatus = HttpStatusCode.OK_200) {
343 const path = '/api/v1/videos/upload' 344 const path = '/api/v1/videos/upload'
344 let defaultChannelId = '1' 345 let defaultChannelId = '1'
345 346
@@ -423,7 +424,13 @@ async function uploadVideo (url: string, accessToken: string, videoAttributesArg
423 .expect(specialStatus) 424 .expect(specialStatus)
424} 425}
425 426
426function updateVideo (url: string, accessToken: string, id: number | string, attributes: VideoAttributes, statusCodeExpected = 204) { 427function updateVideo (
428 url: string,
429 accessToken: string,
430 id: number | string,
431 attributes: VideoAttributes,
432 statusCodeExpected = HttpStatusCode.NO_CONTENT_204
433) {
427 const path = '/api/v1/videos/' + id 434 const path = '/api/v1/videos/' + id
428 const body = {} 435 const body = {}
429 436
@@ -467,7 +474,7 @@ function updateVideo (url: string, accessToken: string, id: number | string, att
467 }) 474 })
468} 475}
469 476
470function rateVideo (url: string, accessToken: string, id: number, rating: string, specialStatus = 204) { 477function rateVideo (url: string, accessToken: string, id: number, rating: string, specialStatus = HttpStatusCode.NO_CONTENT_204) {
471 const path = '/api/v1/videos/' + id + '/rate' 478 const path = '/api/v1/videos/' + id + '/rate'
472 479
473 return request(url) 480 return request(url)