aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/videos
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-12-07 14:32:36 +0100
committerGitHub <noreply@github.com>2020-12-07 14:32:36 +0100
commit2d53be0267acc49cda46707b885096193a1f4e9c (patch)
tree887061a34bc67f40acbb96a6278f9544bf83caeb /shared/extra-utils/videos
parentadc1f09c0dbd997f34028c1c82d1c118dc8ead80 (diff)
downloadPeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.tar.gz
PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.tar.zst
PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.zip
replace numbers with typed http status codes (#3409)
Diffstat (limited to 'shared/extra-utils/videos')
-rw-r--r--shared/extra-utils/videos/live.ts13
-rw-r--r--shared/extra-utils/videos/services.ts3
-rw-r--r--shared/extra-utils/videos/video-blacklist.ts17
-rw-r--r--shared/extra-utils/videos/video-captions.ts9
-rw-r--r--shared/extra-utils/videos/video-change-ownership.ts26
-rw-r--r--shared/extra-utils/videos/video-channels.ts24
-rw-r--r--shared/extra-utils/videos/video-comments.ts19
-rw-r--r--shared/extra-utils/videos/video-history.ts5
-rw-r--r--shared/extra-utils/videos/video-imports.ts10
-rw-r--r--shared/extra-utils/videos/video-playlists.ts31
-rw-r--r--shared/extra-utils/videos/video-streaming-playlists.ts9
-rw-r--r--shared/extra-utils/videos/videos.ts49
12 files changed, 141 insertions, 74 deletions
diff --git a/shared/extra-utils/videos/live.ts b/shared/extra-utils/videos/live.ts
index 522beb8bc..4aa66622b 100644
--- a/shared/extra-utils/videos/live.ts
+++ b/shared/extra-utils/videos/live.ts
@@ -10,8 +10,9 @@ import { buildAbsoluteFixturePath, buildServerDirectory, wait } from '../miscs/m
10import { makeGetRequest, makePutBodyRequest, makeUploadRequest } from '../requests/requests' 10import { makeGetRequest, makePutBodyRequest, makeUploadRequest } from '../requests/requests'
11import { ServerInfo } from '../server/servers' 11import { ServerInfo } from '../server/servers'
12import { getVideoWithToken } from './videos' 12import { getVideoWithToken } from './videos'
13import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
13 14
14function getLive (url: string, token: string, videoId: number | string, statusCodeExpected = 200) { 15function getLive (url: string, token: string, videoId: number | string, statusCodeExpected = HttpStatusCode.OK_200) {
15 const path = '/api/v1/videos/live' 16 const path = '/api/v1/videos/live'
16 17
17 return makeGetRequest({ 18 return makeGetRequest({
@@ -22,7 +23,13 @@ function getLive (url: string, token: string, videoId: number | string, statusCo
22 }) 23 })
23} 24}
24 25
25function updateLive (url: string, token: string, videoId: number | string, fields: LiveVideoUpdate, statusCodeExpected = 204) { 26function updateLive (
27 url: string,
28 token: string,
29 videoId: number | string,
30 fields: LiveVideoUpdate,
31 statusCodeExpected = HttpStatusCode.NO_CONTENT_204
32) {
26 const path = '/api/v1/videos/live' 33 const path = '/api/v1/videos/live'
27 34
28 return makePutBodyRequest({ 35 return makePutBodyRequest({
@@ -34,7 +41,7 @@ function updateLive (url: string, token: string, videoId: number | string, field
34 }) 41 })
35} 42}
36 43
37function createLive (url: string, token: string, fields: LiveVideoCreate, statusCodeExpected = 200) { 44function createLive (url: string, token: string, fields: LiveVideoCreate, statusCodeExpected = HttpStatusCode.OK_200) {
38 const path = '/api/v1/videos/live' 45 const path = '/api/v1/videos/live'
39 46
40 const attaches: any = {} 47 const attaches: any = {}
diff --git a/shared/extra-utils/videos/services.ts b/shared/extra-utils/videos/services.ts
index 1a53dd4cf..e13a788bd 100644
--- a/shared/extra-utils/videos/services.ts
+++ b/shared/extra-utils/videos/services.ts
@@ -1,4 +1,5 @@
1import * as request from 'supertest' 1import * as request from 'supertest'
2import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
2 3
3function getOEmbed (url: string, oembedUrl: string, format?: string, maxHeight?: number, maxWidth?: number) { 4function getOEmbed (url: string, oembedUrl: string, format?: string, maxHeight?: number, maxWidth?: number) {
4 const path = '/services/oembed' 5 const path = '/services/oembed'
@@ -13,7 +14,7 @@ function getOEmbed (url: string, oembedUrl: string, format?: string, maxHeight?:
13 .get(path) 14 .get(path)
14 .query(query) 15 .query(query)
15 .set('Accept', 'application/json') 16 .set('Accept', 'application/json')
16 .expect(200) 17 .expect(HttpStatusCode.OK_200)
17} 18}
18 19
19// --------------------------------------------------------------------------- 20// ---------------------------------------------------------------------------
diff --git a/shared/extra-utils/videos/video-blacklist.ts b/shared/extra-utils/videos/video-blacklist.ts
index ba139ef95..aa1548537 100644
--- a/shared/extra-utils/videos/video-blacklist.ts
+++ b/shared/extra-utils/videos/video-blacklist.ts
@@ -1,6 +1,7 @@
1import * as request from 'supertest' 1import * as request from 'supertest'
2import { VideoBlacklistType } from '../../models/videos' 2import { VideoBlacklistType } from '../../models/videos'
3import { makeGetRequest } from '..' 3import { makeGetRequest } from '..'
4import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
4 5
5function addVideoToBlacklist ( 6function addVideoToBlacklist (
6 url: string, 7 url: string,
@@ -8,7 +9,7 @@ function addVideoToBlacklist (
8 videoId: number | string, 9 videoId: number | string,
9 reason?: string, 10 reason?: string,
10 unfederate?: boolean, 11 unfederate?: boolean,
11 specialStatus = 204 12 specialStatus = HttpStatusCode.NO_CONTENT_204
12) { 13) {
13 const path = '/api/v1/videos/' + videoId + '/blacklist' 14 const path = '/api/v1/videos/' + videoId + '/blacklist'
14 15
@@ -20,7 +21,13 @@ function addVideoToBlacklist (
20 .expect(specialStatus) 21 .expect(specialStatus)
21} 22}
22 23
23function updateVideoBlacklist (url: string, token: string, videoId: number, reason?: string, specialStatus = 204) { 24function updateVideoBlacklist (
25 url: string,
26 token: string,
27 videoId: number,
28 reason?: string,
29 specialStatus = HttpStatusCode.NO_CONTENT_204
30) {
24 const path = '/api/v1/videos/' + videoId + '/blacklist' 31 const path = '/api/v1/videos/' + videoId + '/blacklist'
25 32
26 return request(url) 33 return request(url)
@@ -31,7 +38,7 @@ function updateVideoBlacklist (url: string, token: string, videoId: number, reas
31 .expect(specialStatus) 38 .expect(specialStatus)
32} 39}
33 40
34function removeVideoFromBlacklist (url: string, token: string, videoId: number | string, specialStatus = 204) { 41function removeVideoFromBlacklist (url: string, token: string, videoId: number | string, specialStatus = HttpStatusCode.NO_CONTENT_204) {
35 const path = '/api/v1/videos/' + videoId + '/blacklist' 42 const path = '/api/v1/videos/' + videoId + '/blacklist'
36 43
37 return request(url) 44 return request(url)
@@ -46,9 +53,9 @@ function getBlacklistedVideosList (parameters: {
46 token: string 53 token: string
47 sort?: string 54 sort?: string
48 type?: VideoBlacklistType 55 type?: VideoBlacklistType
49 specialStatus?: number 56 specialStatus?: HttpStatusCode
50}) { 57}) {
51 const { url, token, sort, type, specialStatus = 200 } = parameters 58 const { url, token, sort, type, specialStatus = HttpStatusCode.OK_200 } = parameters
52 const path = '/api/v1/videos/blacklist/' 59 const path = '/api/v1/videos/blacklist/'
53 60
54 const query = { sort, type } 61 const query = { sort, type }
diff --git a/shared/extra-utils/videos/video-captions.ts b/shared/extra-utils/videos/video-captions.ts
index 5bd533bba..62eec7b90 100644
--- a/shared/extra-utils/videos/video-captions.ts
+++ b/shared/extra-utils/videos/video-captions.ts
@@ -2,6 +2,7 @@ import { makeDeleteRequest, makeGetRequest, makeUploadRequest } from '../request
2import * as request from 'supertest' 2import * as request from 'supertest'
3import * as chai from 'chai' 3import * as chai from 'chai'
4import { buildAbsoluteFixturePath } from '../miscs/miscs' 4import { buildAbsoluteFixturePath } from '../miscs/miscs'
5import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
5 6
6const expect = chai.expect 7const expect = chai.expect
7 8
@@ -28,7 +29,7 @@ function createVideoCaption (args: {
28 attaches: { 29 attaches: {
29 captionfile: captionfileAttach 30 captionfile: captionfileAttach
30 }, 31 },
31 statusCodeExpected: args.statusCodeExpected || 204 32 statusCodeExpected: args.statusCodeExpected || HttpStatusCode.NO_CONTENT_204
32 }) 33 })
33} 34}
34 35
@@ -38,7 +39,7 @@ function listVideoCaptions (url: string, videoId: string | number) {
38 return makeGetRequest({ 39 return makeGetRequest({
39 url, 40 url,
40 path, 41 path,
41 statusCodeExpected: 200 42 statusCodeExpected: HttpStatusCode.OK_200
42 }) 43 })
43} 44}
44 45
@@ -49,14 +50,14 @@ function deleteVideoCaption (url: string, token: string, videoId: string | numbe
49 url, 50 url,
50 token, 51 token,
51 path, 52 path,
52 statusCodeExpected: 204 53 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
53 }) 54 })
54} 55}
55 56
56async function testCaptionFile (url: string, captionPath: string, containsString: string) { 57async function testCaptionFile (url: string, captionPath: string, containsString: string) {
57 const res = await request(url) 58 const res = await request(url)
58 .get(captionPath) 59 .get(captionPath)
59 .expect(200) 60 .expect(HttpStatusCode.OK_200)
60 61
61 expect(res.text).to.contain(containsString) 62 expect(res.text).to.contain(containsString)
62} 63}
diff --git a/shared/extra-utils/videos/video-change-ownership.ts b/shared/extra-utils/videos/video-change-ownership.ts
index 371d02000..ef82a7636 100644
--- a/shared/extra-utils/videos/video-change-ownership.ts
+++ b/shared/extra-utils/videos/video-change-ownership.ts
@@ -1,6 +1,13 @@
1import * as request from 'supertest' 1import * as request from 'supertest'
2import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
2 3
3function changeVideoOwnership (url: string, token: string, videoId: number | string, username, expectedStatus = 204) { 4function changeVideoOwnership (
5 url: string,
6 token: string,
7 videoId: number | string,
8 username,
9 expectedStatus = HttpStatusCode.NO_CONTENT_204
10) {
4 const path = '/api/v1/videos/' + videoId + '/give-ownership' 11 const path = '/api/v1/videos/' + videoId + '/give-ownership'
5 12
6 return request(url) 13 return request(url)
@@ -19,11 +26,17 @@ function getVideoChangeOwnershipList (url: string, token: string) {
19 .query({ sort: '-createdAt' }) 26 .query({ sort: '-createdAt' })
20 .set('Accept', 'application/json') 27 .set('Accept', 'application/json')
21 .set('Authorization', 'Bearer ' + token) 28 .set('Authorization', 'Bearer ' + token)
22 .expect(200) 29 .expect(HttpStatusCode.OK_200)
23 .expect('Content-Type', /json/) 30 .expect('Content-Type', /json/)
24} 31}
25 32
26function acceptChangeOwnership (url: string, token: string, ownershipId: string, channelId: number, expectedStatus = 204) { 33function acceptChangeOwnership (
34 url: string,
35 token: string,
36 ownershipId: string,
37 channelId: number,
38 expectedStatus = HttpStatusCode.NO_CONTENT_204
39) {
27 const path = '/api/v1/videos/ownership/' + ownershipId + '/accept' 40 const path = '/api/v1/videos/ownership/' + ownershipId + '/accept'
28 41
29 return request(url) 42 return request(url)
@@ -34,7 +47,12 @@ function acceptChangeOwnership (url: string, token: string, ownershipId: string,
34 .expect(expectedStatus) 47 .expect(expectedStatus)
35} 48}
36 49
37function refuseChangeOwnership (url: string, token: string, ownershipId: string, expectedStatus = 204) { 50function refuseChangeOwnership (
51 url: string,
52 token: string,
53 ownershipId: string,
54 expectedStatus = HttpStatusCode.NO_CONTENT_204
55) {
38 const path = '/api/v1/videos/ownership/' + ownershipId + '/refuse' 56 const path = '/api/v1/videos/ownership/' + ownershipId + '/refuse'
39 57
40 return request(url) 58 return request(url)
diff --git a/shared/extra-utils/videos/video-channels.ts b/shared/extra-utils/videos/video-channels.ts
index 97b68178f..3ff445c2a 100644
--- a/shared/extra-utils/videos/video-channels.ts
+++ b/shared/extra-utils/videos/video-channels.ts
@@ -7,6 +7,7 @@ import { makeGetRequest, updateAvatarRequest } from '../requests/requests'
7import { ServerInfo } from '../server/servers' 7import { ServerInfo } from '../server/servers'
8import { User } from '../../models/users/user.model' 8import { User } from '../../models/users/user.model'
9import { getMyUserInformation } from '../users/users' 9import { getMyUserInformation } from '../users/users'
10import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
10 11
11function getVideoChannelsList (url: string, start: number, count: number, sort?: string, withStats?: boolean) { 12function getVideoChannelsList (url: string, start: number, count: number, sort?: string, withStats?: boolean) {
12 const path = '/api/v1/video-channels' 13 const path = '/api/v1/video-channels'
@@ -20,7 +21,7 @@ function getVideoChannelsList (url: string, start: number, count: number, sort?:
20 if (withStats) req.query({ withStats }) 21 if (withStats) req.query({ withStats })
21 22
22 return req.set('Accept', 'application/json') 23 return req.set('Accept', 'application/json')
23 .expect(200) 24 .expect(HttpStatusCode.OK_200)
24 .expect('Content-Type', /json/) 25 .expect('Content-Type', /json/)
25} 26}
26 27
@@ -30,11 +31,20 @@ function getAccountVideoChannelsList (parameters: {
30 start?: number 31 start?: number
31 count?: number 32 count?: number
32 sort?: string 33 sort?: string
33 specialStatus?: number 34 specialStatus?: HttpStatusCode
34 withStats?: boolean 35 withStats?: boolean
35 search?: string 36 search?: string
36}) { 37}) {
37 const { url, accountName, start, count, sort = 'createdAt', specialStatus = 200, withStats = false, search } = parameters 38 const {
39 url,
40 accountName,
41 start,
42 count,
43 sort = 'createdAt',
44 specialStatus = HttpStatusCode.OK_200,
45 withStats = false,
46 search
47 } = parameters
38 48
39 const path = '/api/v1/accounts/' + accountName + '/video-channels' 49 const path = '/api/v1/accounts/' + accountName + '/video-channels'
40 50
@@ -56,7 +66,7 @@ function addVideoChannel (
56 url: string, 66 url: string,
57 token: string, 67 token: string,
58 videoChannelAttributesArg: VideoChannelCreate, 68 videoChannelAttributesArg: VideoChannelCreate,
59 expectedStatus = 200 69 expectedStatus = HttpStatusCode.OK_200
60) { 70) {
61 const path = '/api/v1/video-channels/' 71 const path = '/api/v1/video-channels/'
62 72
@@ -81,7 +91,7 @@ function updateVideoChannel (
81 token: string, 91 token: string,
82 channelName: string, 92 channelName: string,
83 attributes: VideoChannelUpdate, 93 attributes: VideoChannelUpdate,
84 expectedStatus = 204 94 expectedStatus = HttpStatusCode.NO_CONTENT_204
85) { 95) {
86 const body: any = {} 96 const body: any = {}
87 const path = '/api/v1/video-channels/' + channelName 97 const path = '/api/v1/video-channels/' + channelName
@@ -99,7 +109,7 @@ function updateVideoChannel (
99 .expect(expectedStatus) 109 .expect(expectedStatus)
100} 110}
101 111
102function deleteVideoChannel (url: string, token: string, channelName: string, expectedStatus = 204) { 112function deleteVideoChannel (url: string, token: string, channelName: string, expectedStatus = HttpStatusCode.NO_CONTENT_204) {
103 const path = '/api/v1/video-channels/' + channelName 113 const path = '/api/v1/video-channels/' + channelName
104 114
105 return request(url) 115 return request(url)
@@ -115,7 +125,7 @@ function getVideoChannel (url: string, channelName: string) {
115 return request(url) 125 return request(url)
116 .get(path) 126 .get(path)
117 .set('Accept', 'application/json') 127 .set('Accept', 'application/json')
118 .expect(200) 128 .expect(HttpStatusCode.OK_200)
119 .expect('Content-Type', /json/) 129 .expect('Content-Type', /json/)
120} 130}
121 131
diff --git a/shared/extra-utils/videos/video-comments.ts b/shared/extra-utils/videos/video-comments.ts
index 0b0df81dc..71b9f875a 100644
--- a/shared/extra-utils/videos/video-comments.ts
+++ b/shared/extra-utils/videos/video-comments.ts
@@ -2,6 +2,7 @@
2 2
3import * as request from 'supertest' 3import * as request from 'supertest'
4import { makeDeleteRequest, makeGetRequest } from '../requests/requests' 4import { makeDeleteRequest, makeGetRequest } from '../requests/requests'
5import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
5 6
6function getAdminVideoComments (options: { 7function getAdminVideoComments (options: {
7 url: string 8 url: string
@@ -33,7 +34,7 @@ function getAdminVideoComments (options: {
33 path, 34 path,
34 token, 35 token,
35 query, 36 query,
36 statusCodeExpected: 200 37 statusCodeExpected: HttpStatusCode.OK_200
37 }) 38 })
38} 39}
39 40
@@ -49,7 +50,7 @@ function getVideoCommentThreads (url: string, videoId: number | string, start: n
49 if (token) req.set('Authorization', 'Bearer ' + token) 50 if (token) req.set('Authorization', 'Bearer ' + token)
50 51
51 return req.set('Accept', 'application/json') 52 return req.set('Accept', 'application/json')
52 .expect(200) 53 .expect(HttpStatusCode.OK_200)
53 .expect('Content-Type', /json/) 54 .expect('Content-Type', /json/)
54} 55}
55 56
@@ -62,11 +63,17 @@ function getVideoThreadComments (url: string, videoId: number | string, threadId
62 63
63 if (token) req.set('Authorization', 'Bearer ' + token) 64 if (token) req.set('Authorization', 'Bearer ' + token)
64 65
65 return req.expect(200) 66 return req.expect(HttpStatusCode.OK_200)
66 .expect('Content-Type', /json/) 67 .expect('Content-Type', /json/)
67} 68}
68 69
69function addVideoCommentThread (url: string, token: string, videoId: number | string, text: string, expectedStatus = 200) { 70function addVideoCommentThread (
71 url: string,
72 token: string,
73 videoId: number | string,
74 text: string,
75 expectedStatus = HttpStatusCode.OK_200
76) {
70 const path = '/api/v1/videos/' + videoId + '/comment-threads' 77 const path = '/api/v1/videos/' + videoId + '/comment-threads'
71 78
72 return request(url) 79 return request(url)
@@ -83,7 +90,7 @@ function addVideoCommentReply (
83 videoId: number | string, 90 videoId: number | string,
84 inReplyToCommentId: number, 91 inReplyToCommentId: number,
85 text: string, 92 text: string,
86 expectedStatus = 200 93 expectedStatus = HttpStatusCode.OK_200
87) { 94) {
88 const path = '/api/v1/videos/' + videoId + '/comments/' + inReplyToCommentId 95 const path = '/api/v1/videos/' + videoId + '/comments/' + inReplyToCommentId
89 96
@@ -106,7 +113,7 @@ function deleteVideoComment (
106 token: string, 113 token: string,
107 videoId: number | string, 114 videoId: number | string,
108 commentId: number, 115 commentId: number,
109 statusCodeExpected = 204 116 statusCodeExpected = HttpStatusCode.NO_CONTENT_204
110) { 117) {
111 const path = '/api/v1/videos/' + videoId + '/comments/' + commentId 118 const path = '/api/v1/videos/' + videoId + '/comments/' + commentId
112 119
diff --git a/shared/extra-utils/videos/video-history.ts b/shared/extra-utils/videos/video-history.ts
index dc7095b4d..2d751cf14 100644
--- a/shared/extra-utils/videos/video-history.ts
+++ b/shared/extra-utils/videos/video-history.ts
@@ -1,4 +1,5 @@
1import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' 1import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests'
2import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
2 3
3function userWatchVideo (url: string, token: string, videoId: number | string, currentTime: number, statusCodeExpected = 204) { 4function userWatchVideo (url: string, token: string, videoId: number | string, currentTime: number, statusCodeExpected = 204) {
4 const path = '/api/v1/videos/' + videoId + '/watching' 5 const path = '/api/v1/videos/' + videoId + '/watching'
@@ -14,7 +15,7 @@ function listMyVideosHistory (url: string, token: string) {
14 url, 15 url,
15 path, 16 path,
16 token, 17 token,
17 statusCodeExpected: 200 18 statusCodeExpected: HttpStatusCode.OK_200
18 }) 19 })
19} 20}
20 21
@@ -26,7 +27,7 @@ function removeMyVideosHistory (url: string, token: string, beforeDate?: string)
26 path, 27 path,
27 token, 28 token,
28 fields: beforeDate ? { beforeDate } : {}, 29 fields: beforeDate ? { beforeDate } : {},
29 statusCodeExpected: 204 30 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
30 }) 31 })
31} 32}
32 33
diff --git a/shared/extra-utils/videos/video-imports.ts b/shared/extra-utils/videos/video-imports.ts
index 6249e8a94..52e0075fb 100644
--- a/shared/extra-utils/videos/video-imports.ts
+++ b/shared/extra-utils/videos/video-imports.ts
@@ -1,6 +1,7 @@
1 1
2import { VideoImportCreate } from '../../models/videos' 2import { VideoImportCreate } from '../../models/videos'
3import { makeGetRequest, makeUploadRequest } from '../requests/requests' 3import { makeGetRequest, makeUploadRequest } from '../requests/requests'
4import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
4 5
5function getYoutubeVideoUrl () { 6function getYoutubeVideoUrl () {
6 return 'http://www.youtube.com/watch?v=msX3jv1XdvM' 7 return 'http://www.youtube.com/watch?v=msX3jv1XdvM'
@@ -19,7 +20,12 @@ function getGoodVideoUrl () {
19 return 'https://download.cpy.re/peertube/good_video.mp4' 20 return 'https://download.cpy.re/peertube/good_video.mp4'
20} 21}
21 22
22function importVideo (url: string, token: string, attributes: VideoImportCreate & { torrentfile?: string }, statusCodeExpected = 200) { 23function importVideo (
24 url: string,
25 token: string,
26 attributes: VideoImportCreate & { torrentfile?: string },
27 statusCodeExpected = HttpStatusCode.OK_200
28) {
23 const path = '/api/v1/videos/imports' 29 const path = '/api/v1/videos/imports'
24 30
25 let attaches: any = {} 31 let attaches: any = {}
@@ -46,7 +52,7 @@ function getMyVideoImports (url: string, token: string, sort?: string) {
46 query, 52 query,
47 path, 53 path,
48 token, 54 token,
49 statusCodeExpected: 200 55 statusCodeExpected: HttpStatusCode.OK_200
50 }) 56 })
51} 57}
52 58
diff --git a/shared/extra-utils/videos/video-playlists.ts b/shared/extra-utils/videos/video-playlists.ts
index 5bcc02570..c6f799e5d 100644
--- a/shared/extra-utils/videos/video-playlists.ts
+++ b/shared/extra-utils/videos/video-playlists.ts
@@ -10,6 +10,7 @@ import { root } from '..'
10import { readdir } from 'fs-extra' 10import { readdir } from 'fs-extra'
11import { expect } from 'chai' 11import { expect } from 'chai'
12import { VideoPlaylistType } from '../../models/videos/playlist/video-playlist-type.model' 12import { VideoPlaylistType } from '../../models/videos/playlist/video-playlist-type.model'
13import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
13 14
14function getVideoPlaylistsList (url: string, start: number, count: number, sort?: string) { 15function getVideoPlaylistsList (url: string, start: number, count: number, sort?: string) {
15 const path = '/api/v1/video-playlists' 16 const path = '/api/v1/video-playlists'
@@ -24,7 +25,7 @@ function getVideoPlaylistsList (url: string, start: number, count: number, sort?
24 url, 25 url,
25 path, 26 path,
26 query, 27 query,
27 statusCodeExpected: 200 28 statusCodeExpected: HttpStatusCode.OK_200
28 }) 29 })
29} 30}
30 31
@@ -41,7 +42,7 @@ function getVideoChannelPlaylistsList (url: string, videoChannelName: string, st
41 url, 42 url,
42 path, 43 path,
43 query, 44 query,
44 statusCodeExpected: 200 45 statusCodeExpected: HttpStatusCode.OK_200
45 }) 46 })
46} 47}
47 48
@@ -59,7 +60,7 @@ function getAccountPlaylistsList (url: string, accountName: string, start: numbe
59 url, 60 url,
60 path, 61 path,
61 query, 62 query,
62 statusCodeExpected: 200 63 statusCodeExpected: HttpStatusCode.OK_200
63 }) 64 })
64} 65}
65 66
@@ -86,11 +87,11 @@ function getAccountPlaylistsListWithToken (
86 token, 87 token,
87 path, 88 path,
88 query, 89 query,
89 statusCodeExpected: 200 90 statusCodeExpected: HttpStatusCode.OK_200
90 }) 91 })
91} 92}
92 93
93function getVideoPlaylist (url: string, playlistId: number | string, statusCodeExpected = 200) { 94function getVideoPlaylist (url: string, playlistId: number | string, statusCodeExpected = HttpStatusCode.OK_200) {
94 const path = '/api/v1/video-playlists/' + playlistId 95 const path = '/api/v1/video-playlists/' + playlistId
95 96
96 return makeGetRequest({ 97 return makeGetRequest({
@@ -100,7 +101,7 @@ function getVideoPlaylist (url: string, playlistId: number | string, statusCodeE
100 }) 101 })
101} 102}
102 103
103function getVideoPlaylistWithToken (url: string, token: string, playlistId: number | string, statusCodeExpected = 200) { 104function getVideoPlaylistWithToken (url: string, token: string, playlistId: number | string, statusCodeExpected = HttpStatusCode.OK_200) {
104 const path = '/api/v1/video-playlists/' + playlistId 105 const path = '/api/v1/video-playlists/' + playlistId
105 106
106 return makeGetRequest({ 107 return makeGetRequest({
@@ -111,7 +112,7 @@ function getVideoPlaylistWithToken (url: string, token: string, playlistId: numb
111 }) 112 })
112} 113}
113 114
114function deleteVideoPlaylist (url: string, token: string, playlistId: number | string, statusCodeExpected = 204) { 115function deleteVideoPlaylist (url: string, token: string, playlistId: number | string, statusCodeExpected = HttpStatusCode.NO_CONTENT_204) {
115 const path = '/api/v1/video-playlists/' + playlistId 116 const path = '/api/v1/video-playlists/' + playlistId
116 117
117 return makeDeleteRequest({ 118 return makeDeleteRequest({
@@ -143,7 +144,7 @@ function createVideoPlaylist (options: {
143 token: options.token, 144 token: options.token,
144 fields, 145 fields,
145 attaches, 146 attaches,
146 statusCodeExpected: options.expectedStatus || 200 147 statusCodeExpected: options.expectedStatus || HttpStatusCode.OK_200
147 }) 148 })
148} 149}
149 150
@@ -169,7 +170,7 @@ function updateVideoPlaylist (options: {
169 token: options.token, 170 token: options.token,
170 fields, 171 fields,
171 attaches, 172 attaches,
172 statusCodeExpected: options.expectedStatus || 204 173 statusCodeExpected: options.expectedStatus || HttpStatusCode.NO_CONTENT_204
173 }) 174 })
174} 175}
175 176
@@ -189,7 +190,7 @@ async function addVideoInPlaylist (options: {
189 path, 190 path,
190 token: options.token, 191 token: options.token,
191 fields: options.elementAttrs, 192 fields: options.elementAttrs,
192 statusCodeExpected: options.expectedStatus || 200 193 statusCodeExpected: options.expectedStatus || HttpStatusCode.OK_200
193 }) 194 })
194} 195}
195 196
@@ -208,7 +209,7 @@ function updateVideoPlaylistElement (options: {
208 path, 209 path,
209 token: options.token, 210 token: options.token,
210 fields: options.elementAttrs, 211 fields: options.elementAttrs,
211 statusCodeExpected: options.expectedStatus || 204 212 statusCodeExpected: options.expectedStatus || HttpStatusCode.NO_CONTENT_204
212 }) 213 })
213} 214}
214 215
@@ -225,7 +226,7 @@ function removeVideoFromPlaylist (options: {
225 url: options.url, 226 url: options.url,
226 path, 227 path,
227 token: options.token, 228 token: options.token,
228 statusCodeExpected: options.expectedStatus || 204 229 statusCodeExpected: options.expectedStatus || HttpStatusCode.NO_CONTENT_204
229 }) 230 })
230} 231}
231 232
@@ -247,7 +248,7 @@ function reorderVideosPlaylist (options: {
247 path, 248 path,
248 token: options.token, 249 token: options.token,
249 fields: options.elementAttrs, 250 fields: options.elementAttrs,
250 statusCodeExpected: options.expectedStatus || 204 251 statusCodeExpected: options.expectedStatus || HttpStatusCode.NO_CONTENT_204
251 }) 252 })
252} 253}
253 254
@@ -274,7 +275,7 @@ function getVideoPlaylistPrivacies (url: string) {
274 return makeGetRequest({ 275 return makeGetRequest({
275 url, 276 url,
276 path, 277 path,
277 statusCodeExpected: 200 278 statusCodeExpected: HttpStatusCode.OK_200
278 }) 279 })
279} 280}
280 281
@@ -286,7 +287,7 @@ function doVideosExistInMyPlaylist (url: string, token: string, videoIds: number
286 token, 287 token,
287 path, 288 path,
288 query: { videoIds }, 289 query: { videoIds },
289 statusCodeExpected: 200 290 statusCodeExpected: HttpStatusCode.OK_200
290 }) 291 })
291} 292}
292 293
diff --git a/shared/extra-utils/videos/video-streaming-playlists.ts b/shared/extra-utils/videos/video-streaming-playlists.ts
index b386e77c3..99c2e1880 100644
--- a/shared/extra-utils/videos/video-streaming-playlists.ts
+++ b/shared/extra-utils/videos/video-streaming-playlists.ts
@@ -2,16 +2,17 @@ import { makeRawRequest } from '../requests/requests'
2import { sha256 } from '../../../server/helpers/core-utils' 2import { sha256 } from '../../../server/helpers/core-utils'
3import { VideoStreamingPlaylist } from '../../models/videos/video-streaming-playlist.model' 3import { VideoStreamingPlaylist } from '../../models/videos/video-streaming-playlist.model'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
5 6
6function getPlaylist (url: string, statusCodeExpected = 200) { 7function getPlaylist (url: string, statusCodeExpected = HttpStatusCode.OK_200) {
7 return makeRawRequest(url, statusCodeExpected) 8 return makeRawRequest(url, statusCodeExpected)
8} 9}
9 10
10function getSegment (url: string, statusCodeExpected = 200, range?: string) { 11function getSegment (url: string, statusCodeExpected = HttpStatusCode.OK_200, range?: string) {
11 return makeRawRequest(url, statusCodeExpected, range) 12 return makeRawRequest(url, statusCodeExpected, range)
12} 13}
13 14
14function getSegmentSha256 (url: string, statusCodeExpected = 200) { 15function getSegmentSha256 (url: string, statusCodeExpected = HttpStatusCode.OK_200) {
15 return makeRawRequest(url, statusCodeExpected) 16 return makeRawRequest(url, statusCodeExpected)
16} 17}
17 18
@@ -33,7 +34,7 @@ async function checkSegmentHash (
33 const offset = parseInt(matches[2], 10) 34 const offset = parseInt(matches[2], 10)
34 const range = `${offset}-${offset + length - 1}` 35 const range = `${offset}-${offset + length - 1}`
35 36
36 const res2 = await getSegment(`${baseUrlSegment}/${videoUUID}/${videoName}`, 206, `bytes=${range}`) 37 const res2 = await getSegment(`${baseUrlSegment}/${videoUUID}/${videoName}`, HttpStatusCode.PARTIAL_CONTENT_206, `bytes=${range}`)
37 38
38 const resSha = await getSegmentSha256(hlsPlaylist.segmentsSha256Url) 39 const resSha = await getSegmentSha256(hlsPlaylist.segmentsSha256Url)
39 40
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)