aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared
diff options
context:
space:
mode:
Diffstat (limited to 'shared')
-rw-r--r--shared/core-utils/miscs/index.ts2
-rw-r--r--shared/extra-utils/bulk/bulk-command.ts4
-rw-r--r--shared/extra-utils/custom-pages/custom-pages-command.ts2
-rw-r--r--shared/extra-utils/feeds/feeds-command.ts2
-rw-r--r--shared/extra-utils/logs/logs-command.ts2
-rw-r--r--shared/extra-utils/miscs/checks.ts4
-rw-r--r--shared/extra-utils/moderation/abuses-command.ts2
-rw-r--r--shared/extra-utils/overviews/overviews-command.ts2
-rw-r--r--shared/extra-utils/requests/check-api-params.ts10
-rw-r--r--shared/extra-utils/requests/requests.ts256
-rw-r--r--shared/extra-utils/search/search-command.ts2
-rw-r--r--shared/extra-utils/server/config-command.ts4
-rw-r--r--shared/extra-utils/server/contact-form-command.ts2
-rw-r--r--shared/extra-utils/server/debug-command.ts2
-rw-r--r--shared/extra-utils/server/follows-command.ts2
-rw-r--r--shared/extra-utils/server/jobs-command.ts2
-rw-r--r--shared/extra-utils/server/plugins-command.ts2
-rw-r--r--shared/extra-utils/server/redundancy-command.ts2
-rw-r--r--shared/extra-utils/server/server.ts2
-rw-r--r--shared/extra-utils/server/servers-command.ts2
-rw-r--r--shared/extra-utils/server/stats-command.ts2
-rw-r--r--shared/extra-utils/shared/abstract-command.ts66
-rw-r--r--shared/extra-utils/users/accounts-command.ts2
-rw-r--r--shared/extra-utils/users/blocklist-command.ts2
-rw-r--r--shared/extra-utils/users/index.ts1
-rw-r--r--shared/extra-utils/users/login-command.ts10
-rw-r--r--shared/extra-utils/users/notifications-command.ts2
-rw-r--r--shared/extra-utils/users/subscriptions-command.ts2
-rw-r--r--shared/extra-utils/users/users-command.ts2
-rw-r--r--shared/extra-utils/users/users.ts20
-rw-r--r--shared/extra-utils/videos/blacklist-command.ts2
-rw-r--r--shared/extra-utils/videos/captions-command.ts2
-rw-r--r--shared/extra-utils/videos/captions.ts2
-rw-r--r--shared/extra-utils/videos/change-ownership-command.ts2
-rw-r--r--shared/extra-utils/videos/channels-command.ts2
-rw-r--r--shared/extra-utils/videos/comments-command.ts2
-rw-r--r--shared/extra-utils/videos/history-command.ts2
-rw-r--r--shared/extra-utils/videos/imports-command.ts2
-rw-r--r--shared/extra-utils/videos/live-command.ts2
-rw-r--r--shared/extra-utils/videos/playlists-command.ts2
-rw-r--r--shared/extra-utils/videos/services-command.ts2
-rw-r--r--shared/extra-utils/videos/streaming-playlists-command.ts3
-rw-r--r--shared/extra-utils/videos/streaming-playlists.ts2
-rw-r--r--shared/extra-utils/videos/videos-command.ts36
-rw-r--r--shared/extra-utils/videos/videos.ts2
-rw-r--r--shared/models/http/http-error-codes.ts (renamed from shared/core-utils/miscs/http-error-codes.ts)0
-rw-r--r--shared/models/http/http-methods.ts (renamed from shared/core-utils/miscs/http-methods.ts)0
-rw-r--r--shared/models/http/index.ts2
-rw-r--r--shared/models/index.ts1
-rw-r--r--shared/models/server/peertube-problem-document.model.ts2
50 files changed, 204 insertions, 283 deletions
diff --git a/shared/core-utils/miscs/index.ts b/shared/core-utils/miscs/index.ts
index 251df1de2..afd147f24 100644
--- a/shared/core-utils/miscs/index.ts
+++ b/shared/core-utils/miscs/index.ts
@@ -1,5 +1,3 @@
1export * from './date' 1export * from './date'
2export * from './miscs' 2export * from './miscs'
3export * from './types' 3export * from './types'
4export * from './http-error-codes'
5export * from './http-methods'
diff --git a/shared/extra-utils/bulk/bulk-command.ts b/shared/extra-utils/bulk/bulk-command.ts
index 6dac6034f..b5c5673ce 100644
--- a/shared/extra-utils/bulk/bulk-command.ts
+++ b/shared/extra-utils/bulk/bulk-command.ts
@@ -1,6 +1,4 @@
1 1import { BulkRemoveCommentsOfBody, HttpStatusCode } from '@shared/models'
2import { BulkRemoveCommentsOfBody } from '@shared/models/bulk/bulk-remove-comments-of-body.model'
3import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
4import { AbstractCommand, OverrideCommandOptions } from '../shared' 2import { AbstractCommand, OverrideCommandOptions } from '../shared'
5 3
6export class BulkCommand extends AbstractCommand { 4export class BulkCommand extends AbstractCommand {
diff --git a/shared/extra-utils/custom-pages/custom-pages-command.ts b/shared/extra-utils/custom-pages/custom-pages-command.ts
index 0dd77503e..6042233d4 100644
--- a/shared/extra-utils/custom-pages/custom-pages-command.ts
+++ b/shared/extra-utils/custom-pages/custom-pages-command.ts
@@ -1,5 +1,5 @@
1import { CustomPage } from '@shared/models' 1import { CustomPage } from '@shared/models'
2import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' 2import { HttpStatusCode } from '@shared/models'
3import { AbstractCommand, OverrideCommandOptions } from '../shared' 3import { AbstractCommand, OverrideCommandOptions } from '../shared'
4 4
5export class CustomPagesCommand extends AbstractCommand { 5export class CustomPagesCommand extends AbstractCommand {
diff --git a/shared/extra-utils/feeds/feeds-command.ts b/shared/extra-utils/feeds/feeds-command.ts
index 2da4110a7..3c95f9536 100644
--- a/shared/extra-utils/feeds/feeds-command.ts
+++ b/shared/extra-utils/feeds/feeds-command.ts
@@ -1,5 +1,5 @@
1 1
2import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' 2import { HttpStatusCode } from '@shared/models'
3import { AbstractCommand, OverrideCommandOptions } from '../shared' 3import { AbstractCommand, OverrideCommandOptions } from '../shared'
4 4
5type FeedType = 'videos' | 'video-comments' | 'subscriptions' 5type FeedType = 'videos' | 'video-comments' | 'subscriptions'
diff --git a/shared/extra-utils/logs/logs-command.ts b/shared/extra-utils/logs/logs-command.ts
index f34c58c47..5912e814f 100644
--- a/shared/extra-utils/logs/logs-command.ts
+++ b/shared/extra-utils/logs/logs-command.ts
@@ -1,4 +1,4 @@
1import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' 1import { HttpStatusCode } from '@shared/models'
2import { LogLevel } from '../../models/server/log-level.type' 2import { LogLevel } from '../../models/server/log-level.type'
3import { AbstractCommand, OverrideCommandOptions } from '../shared' 3import { AbstractCommand, OverrideCommandOptions } from '../shared'
4 4
diff --git a/shared/extra-utils/miscs/checks.ts b/shared/extra-utils/miscs/checks.ts
index c81460330..7fc92f804 100644
--- a/shared/extra-utils/miscs/checks.ts
+++ b/shared/extra-utils/miscs/checks.ts
@@ -4,7 +4,7 @@ import { expect } from 'chai'
4import { pathExists, readFile } from 'fs-extra' 4import { pathExists, readFile } from 'fs-extra'
5import { join } from 'path' 5import { join } from 'path'
6import { root } from '@server/helpers/core-utils' 6import { root } from '@server/helpers/core-utils'
7import { HttpStatusCode } from '@shared/core-utils' 7import { HttpStatusCode } from '@shared/models'
8import { makeGetRequest } from '../requests' 8import { makeGetRequest } from '../requests'
9import { PeerTubeServer } from '../server' 9import { PeerTubeServer } from '../server'
10 10
@@ -20,7 +20,7 @@ async function testImage (url: string, imageName: string, imagePath: string, ext
20 const res = await makeGetRequest({ 20 const res = await makeGetRequest({
21 url, 21 url,
22 path: imagePath, 22 path: imagePath,
23 statusCodeExpected: HttpStatusCode.OK_200 23 expectedStatus: HttpStatusCode.OK_200
24 }) 24 })
25 25
26 const body = res.body 26 const body = res.body
diff --git a/shared/extra-utils/moderation/abuses-command.ts b/shared/extra-utils/moderation/abuses-command.ts
index 03da0c85a..72f2c9951 100644
--- a/shared/extra-utils/moderation/abuses-command.ts
+++ b/shared/extra-utils/moderation/abuses-command.ts
@@ -10,7 +10,7 @@ import {
10 ResultList, 10 ResultList,
11 UserAbuse 11 UserAbuse
12} from '@shared/models' 12} from '@shared/models'
13import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' 13import { HttpStatusCode } from '@shared/models'
14import { AbstractCommand, OverrideCommandOptions } from '../shared' 14import { AbstractCommand, OverrideCommandOptions } from '../shared'
15import { unwrapBody } from '../requests/requests' 15import { unwrapBody } from '../requests/requests'
16 16
diff --git a/shared/extra-utils/overviews/overviews-command.ts b/shared/extra-utils/overviews/overviews-command.ts
index e15644d94..d4a2ac254 100644
--- a/shared/extra-utils/overviews/overviews-command.ts
+++ b/shared/extra-utils/overviews/overviews-command.ts
@@ -1,4 +1,4 @@
1import { HttpStatusCode } from '@shared/core-utils' 1import { HttpStatusCode } from '@shared/models'
2import { VideosOverview } from '@shared/models' 2import { VideosOverview } from '@shared/models'
3import { AbstractCommand, OverrideCommandOptions } from '../shared' 3import { AbstractCommand, OverrideCommandOptions } from '../shared'
4 4
diff --git a/shared/extra-utils/requests/check-api-params.ts b/shared/extra-utils/requests/check-api-params.ts
index 7df63b004..26ba1e913 100644
--- a/shared/extra-utils/requests/check-api-params.ts
+++ b/shared/extra-utils/requests/check-api-params.ts
@@ -1,4 +1,4 @@
1import { HttpStatusCode } from '@shared/core-utils' 1import { HttpStatusCode } from '@shared/models'
2import { makeGetRequest } from './requests' 2import { makeGetRequest } from './requests'
3 3
4function checkBadStartPagination (url: string, path: string, token?: string, query = {}) { 4function checkBadStartPagination (url: string, path: string, token?: string, query = {}) {
@@ -7,7 +7,7 @@ function checkBadStartPagination (url: string, path: string, token?: string, que
7 path, 7 path,
8 token, 8 token,
9 query: { ...query, start: 'hello' }, 9 query: { ...query, start: 'hello' },
10 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 10 expectedStatus: HttpStatusCode.BAD_REQUEST_400
11 }) 11 })
12} 12}
13 13
@@ -17,7 +17,7 @@ async function checkBadCountPagination (url: string, path: string, token?: strin
17 path, 17 path,
18 token, 18 token,
19 query: { ...query, count: 'hello' }, 19 query: { ...query, count: 'hello' },
20 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 20 expectedStatus: HttpStatusCode.BAD_REQUEST_400
21 }) 21 })
22 22
23 await makeGetRequest({ 23 await makeGetRequest({
@@ -25,7 +25,7 @@ async function checkBadCountPagination (url: string, path: string, token?: strin
25 path, 25 path,
26 token, 26 token,
27 query: { ...query, count: 2000 }, 27 query: { ...query, count: 2000 },
28 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 28 expectedStatus: HttpStatusCode.BAD_REQUEST_400
29 }) 29 })
30} 30}
31 31
@@ -35,7 +35,7 @@ function checkBadSortPagination (url: string, path: string, token?: string, quer
35 path, 35 path,
36 token, 36 token,
37 query: { ...query, sort: 'hello' }, 37 query: { ...query, sort: 'hello' },
38 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 38 expectedStatus: HttpStatusCode.BAD_REQUEST_400
39 }) 39 })
40} 40}
41 41
diff --git a/shared/extra-utils/requests/requests.ts b/shared/extra-utils/requests/requests.ts
index 60c9b938b..70f790222 100644
--- a/shared/extra-utils/requests/requests.ts
+++ b/shared/extra-utils/requests/requests.ts
@@ -1,111 +1,82 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */ 1/* eslint-disable @typescript-eslint/no-floating-promises */
2 2
3import { isAbsolute, join } from 'path'
4import { decode } from 'querystring' 3import { decode } from 'querystring'
5import * as request from 'supertest' 4import * as request from 'supertest'
6import { URL } from 'url' 5import { URL } from 'url'
7import { HttpStatusCode } from '@shared/core-utils' 6import { HttpStatusCode } from '@shared/models'
8import { buildAbsoluteFixturePath, root } from '../miscs/tests' 7import { buildAbsoluteFixturePath } from '../miscs/tests'
9 8
10function makeRawRequest (url: string, statusCodeExpected?: HttpStatusCode, range?: string) { 9export type CommonRequestParams = {
11 const { host, protocol, pathname } = new URL(url)
12
13 return makeGetRequest({ url: `${protocol}//${host}`, path: pathname, statusCodeExpected, range })
14}
15
16function makeGetRequest (options: {
17 url: string 10 url: string
18 path?: string 11 path?: string
19 query?: any
20 token?: string
21 statusCodeExpected?: HttpStatusCode
22 contentType?: string 12 contentType?: string
23 range?: string 13 range?: string
24 redirects?: number 14 redirects?: number
25 accept?: string 15 accept?: string
26 host?: string 16 host?: string
27}) { 17 token?: string
28 if (!options.statusCodeExpected) options.statusCodeExpected = HttpStatusCode.BAD_REQUEST_400 18 headers?: { [ name: string ]: string }
29 if (options.contentType === undefined) options.contentType = 'application/json' 19 type?: string
30 20 xForwardedFor?: string
31 const req = request(options.url).get(options.path) 21 expectedStatus?: HttpStatusCode
22}
32 23
33 if (options.contentType) req.set('Accept', options.contentType) 24function makeRawRequest (url: string, expectedStatus?: HttpStatusCode, range?: string) {
34 if (options.token) req.set('Authorization', 'Bearer ' + options.token) 25 const { host, protocol, pathname } = new URL(url)
35 if (options.query) req.query(options.query)
36 if (options.range) req.set('Range', options.range)
37 if (options.accept) req.set('Accept', options.accept)
38 if (options.host) req.set('Host', options.host)
39 if (options.redirects) req.redirects(options.redirects)
40 26
41 return req.expect(options.statusCodeExpected) 27 return makeGetRequest({ url: `${protocol}//${host}`, path: pathname, expectedStatus, range })
42} 28}
43 29
44function makeDeleteRequest (options: { 30function makeGetRequest (options: CommonRequestParams & {
45 url: string 31 query?: any
46 path: string
47 token?: string
48 statusCodeExpected?: HttpStatusCode
49}) { 32}) {
50 if (!options.statusCodeExpected) options.statusCodeExpected = HttpStatusCode.BAD_REQUEST_400 33 const req = request(options.url).get(options.path)
34 .query(options.query)
51 35
52 const req = request(options.url) 36 return buildRequest(req, { contentType: 'application/json', expectedStatus: HttpStatusCode.BAD_REQUEST_400, ...options })
53 .delete(options.path) 37}
54 .set('Accept', 'application/json')
55 38
56 if (options.token) req.set('Authorization', 'Bearer ' + options.token) 39function makeHTMLRequest (url: string, path: string) {
40 return makeGetRequest({
41 url,
42 path,
43 accept: 'text/html',
44 expectedStatus: HttpStatusCode.OK_200
45 })
46}
57 47
58 return req.expect(options.statusCodeExpected) 48function makeActivityPubGetRequest (url: string, path: string, expectedStatus = HttpStatusCode.OK_200) {
49 return makeGetRequest({
50 url,
51 path,
52 expectedStatus: expectedStatus,
53 accept: 'application/activity+json,text/html;q=0.9,\\*/\\*;q=0.8'
54 })
59} 55}
60 56
61function makeUploadRequest (options: { 57function makeDeleteRequest (options: CommonRequestParams) {
62 url: string 58 const req = request(options.url).delete(options.path)
59
60 return buildRequest(req, { accept: 'application/json', expectedStatus: HttpStatusCode.BAD_REQUEST_400, ...options })
61}
62
63function makeUploadRequest (options: CommonRequestParams & {
63 method?: 'POST' | 'PUT' 64 method?: 'POST' | 'PUT'
64 path: string
65 token?: string
66 65
67 fields: { [ fieldName: string ]: any } 66 fields: { [ fieldName: string ]: any }
68 attaches?: { [ attachName: string ]: any | any[] } 67 attaches?: { [ attachName: string ]: any | any[] }
69
70 headers?: { [ name: string ]: string }
71
72 statusCodeExpected?: HttpStatusCode
73}) { 68}) {
74 if (options.statusCodeExpected === undefined) { 69 let req = options.method === 'PUT'
75 options.statusCodeExpected = HttpStatusCode.BAD_REQUEST_400 70 ? request(options.url).put(options.path)
76 } 71 : request(options.url).post(options.path)
77 72
78 let req: request.Test 73 req = buildRequest(req, { accept: 'application/json', expectedStatus: HttpStatusCode.BAD_REQUEST_400, ...options })
79 if (options.method === 'PUT') {
80 req = request(options.url).put(options.path)
81 } else {
82 req = request(options.url).post(options.path)
83 }
84 74
85 req.set('Accept', 'application/json') 75 buildFields(req, options.fields)
86
87 if (options.token) req.set('Authorization', 'Bearer ' + options.token)
88
89 Object.keys(options.headers || {}).forEach(name => {
90 req.set(name, options.headers[name])
91 })
92
93 Object.keys(options.fields).forEach(field => {
94 const value = options.fields[field]
95
96 if (value === undefined) return
97
98 if (Array.isArray(value)) {
99 for (let i = 0; i < value.length; i++) {
100 req.field(field + '[' + i + ']', value[i])
101 }
102 } else {
103 req.field(field, value)
104 }
105 })
106 76
107 Object.keys(options.attaches || {}).forEach(attach => { 77 Object.keys(options.attaches || {}).forEach(attach => {
108 const value = options.attaches[attach] 78 const value = options.attaches[attach]
79
109 if (Array.isArray(value)) { 80 if (Array.isArray(value)) {
110 req.attach(attach, buildAbsoluteFixturePath(value[0]), value[1]) 81 req.attach(attach, buildAbsoluteFixturePath(value[0]), value[1])
111 } else { 82 } else {
@@ -113,40 +84,16 @@ function makeUploadRequest (options: {
113 } 84 }
114 }) 85 })
115 86
116 if (options.statusCodeExpected) {
117 req.expect(options.statusCodeExpected)
118 }
119
120 return req 87 return req
121} 88}
122 89
123function makePostBodyRequest (options: { 90function makePostBodyRequest (options: CommonRequestParams & {
124 url: string
125 path: string
126 token?: string
127 fields?: { [ fieldName: string ]: any } 91 fields?: { [ fieldName: string ]: any }
128 headers?: { [ name: string ]: string }
129 type?: string
130 xForwardedFor?: string
131 statusCodeExpected?: HttpStatusCode
132}) { 92}) {
133 if (!options.fields) options.fields = {} 93 const req = request(options.url).post(options.path)
134 if (!options.statusCodeExpected) options.statusCodeExpected = HttpStatusCode.BAD_REQUEST_400 94 .send(options.fields)
135
136 const req = request(options.url)
137 .post(options.path)
138 .set('Accept', 'application/json')
139 95
140 if (options.token) req.set('Authorization', 'Bearer ' + options.token) 96 return buildRequest(req, { accept: 'application/json', expectedStatus: HttpStatusCode.BAD_REQUEST_400, ...options })
141 if (options.xForwardedFor) req.set('X-Forwarded-For', options.xForwardedFor)
142 if (options.type) req.type(options.type)
143
144 Object.keys(options.headers || {}).forEach(name => {
145 req.set(name, options.headers[name])
146 })
147
148 return req.send(options.fields)
149 .expect(options.statusCodeExpected)
150} 97}
151 98
152function makePutBodyRequest (options: { 99function makePutBodyRequest (options: {
@@ -154,58 +101,12 @@ function makePutBodyRequest (options: {
154 path: string 101 path: string
155 token?: string 102 token?: string
156 fields: { [ fieldName: string ]: any } 103 fields: { [ fieldName: string ]: any }
157 statusCodeExpected?: HttpStatusCode 104 expectedStatus?: HttpStatusCode
158}) {
159 if (!options.statusCodeExpected) options.statusCodeExpected = HttpStatusCode.BAD_REQUEST_400
160
161 const req = request(options.url)
162 .put(options.path)
163 .set('Accept', 'application/json')
164
165 if (options.token) req.set('Authorization', 'Bearer ' + options.token)
166
167 return req.send(options.fields)
168 .expect(options.statusCodeExpected)
169}
170
171function makeHTMLRequest (url: string, path: string) {
172 return request(url)
173 .get(path)
174 .set('Accept', 'text/html')
175 .expect(HttpStatusCode.OK_200)
176}
177
178function makeActivityPubGetRequest (url: string, path: string, expectedStatus = HttpStatusCode.OK_200) {
179 return makeGetRequest({
180 url,
181 path,
182 statusCodeExpected: expectedStatus,
183 accept: 'application/activity+json,text/html;q=0.9,\\*/\\*;q=0.8'
184 })
185}
186
187function updateImageRequest (options: {
188 url: string
189 path: string
190 accessToken: string
191 fixture: string
192 fieldname: string
193}) { 105}) {
194 let filePath = '' 106 const req = request(options.url).put(options.path)
195 if (isAbsolute(options.fixture)) { 107 .send(options.fields)
196 filePath = options.fixture
197 } else {
198 filePath = join(root(), 'server', 'tests', 'fixtures', options.fixture)
199 }
200 108
201 return makeUploadRequest({ 109 return buildRequest(req, { accept: 'application/json', expectedStatus: HttpStatusCode.BAD_REQUEST_400, ...options })
202 url: options.url,
203 path: options.path,
204 token: options.accessToken,
205 fields: {},
206 attaches: { [options.fieldname]: filePath },
207 statusCodeExpected: HttpStatusCode.OK_200
208 })
209} 110}
210 111
211function decodeQueryString (path: string) { 112function decodeQueryString (path: string) {
@@ -233,6 +134,49 @@ export {
233 makeRawRequest, 134 makeRawRequest,
234 makeActivityPubGetRequest, 135 makeActivityPubGetRequest,
235 unwrapBody, 136 unwrapBody,
236 unwrapText, 137 unwrapText
237 updateImageRequest 138}
139
140// ---------------------------------------------------------------------------
141
142function buildRequest (req: request.Test, options: CommonRequestParams) {
143 if (options.contentType) req.set('Accept', options.contentType)
144 if (options.token) req.set('Authorization', 'Bearer ' + options.token)
145 if (options.range) req.set('Range', options.range)
146 if (options.accept) req.set('Accept', options.accept)
147 if (options.host) req.set('Host', options.host)
148 if (options.redirects) req.redirects(options.redirects)
149 if (options.expectedStatus) req.expect(options.expectedStatus)
150 if (options.xForwardedFor) req.set('X-Forwarded-For', options.xForwardedFor)
151 if (options.type) req.type(options.type)
152
153 Object.keys(options.headers || {}).forEach(name => {
154 req.set(name, options.headers[name])
155 })
156
157 return req
158}
159
160function buildFields (req: request.Test, fields: { [ fieldName: string ]: any }, namespace?: string) {
161 if (!fields) return
162
163 let formKey: string
164
165 for (const key of Object.keys(fields)) {
166 if (namespace) formKey = `${namespace}[${key}]`
167 else formKey = key
168
169 if (fields[key] === undefined) continue
170
171 if (Array.isArray(fields[key]) && fields[key].length === 0) {
172 req.field(key, null)
173 continue
174 }
175
176 if (fields[key] !== null && typeof fields[key] === 'object') {
177 buildFields(req, fields[key], formKey)
178 } else {
179 req.field(formKey, fields[key])
180 }
181 }
238} 182}
diff --git a/shared/extra-utils/search/search-command.ts b/shared/extra-utils/search/search-command.ts
index 7539a21ec..09f5d3f1d 100644
--- a/shared/extra-utils/search/search-command.ts
+++ b/shared/extra-utils/search/search-command.ts
@@ -7,7 +7,7 @@ import {
7 VideoPlaylistsSearchQuery, 7 VideoPlaylistsSearchQuery,
8 VideosSearchQuery 8 VideosSearchQuery
9} from '@shared/models' 9} from '@shared/models'
10import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' 10import { HttpStatusCode } from '@shared/models'
11import { AbstractCommand, OverrideCommandOptions } from '../shared' 11import { AbstractCommand, OverrideCommandOptions } from '../shared'
12 12
13export class SearchCommand extends AbstractCommand { 13export class SearchCommand extends AbstractCommand {
diff --git a/shared/extra-utils/server/config-command.ts b/shared/extra-utils/server/config-command.ts
index f5d7fc5e3..6e875fdf6 100644
--- a/shared/extra-utils/server/config-command.ts
+++ b/shared/extra-utils/server/config-command.ts
@@ -1,6 +1,6 @@
1import { merge } from 'lodash' 1import { merge } from 'lodash'
2import { DeepPartial, HttpStatusCode } from '@shared/core-utils' 2import { DeepPartial } from '@shared/core-utils'
3import { About, ServerConfig } from '@shared/models' 3import { About, ServerConfig, HttpStatusCode } from '@shared/models'
4import { CustomConfig } from '../../models/server/custom-config.model' 4import { CustomConfig } from '../../models/server/custom-config.model'
5import { AbstractCommand, OverrideCommandOptions } from '../shared' 5import { AbstractCommand, OverrideCommandOptions } from '../shared'
6 6
diff --git a/shared/extra-utils/server/contact-form-command.ts b/shared/extra-utils/server/contact-form-command.ts
index 8d034552b..0e8fd6d84 100644
--- a/shared/extra-utils/server/contact-form-command.ts
+++ b/shared/extra-utils/server/contact-form-command.ts
@@ -1,4 +1,4 @@
1import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' 1import { HttpStatusCode } from '@shared/models'
2import { ContactForm } from '../../models/server' 2import { ContactForm } from '../../models/server'
3import { AbstractCommand, OverrideCommandOptions } from '../shared' 3import { AbstractCommand, OverrideCommandOptions } from '../shared'
4 4
diff --git a/shared/extra-utils/server/debug-command.ts b/shared/extra-utils/server/debug-command.ts
index 8b24b3067..36704836d 100644
--- a/shared/extra-utils/server/debug-command.ts
+++ b/shared/extra-utils/server/debug-command.ts
@@ -1,5 +1,5 @@
1import { Debug, SendDebugCommand } from '@shared/models' 1import { Debug, SendDebugCommand } from '@shared/models'
2import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' 2import { HttpStatusCode } from '@shared/models'
3import { AbstractCommand, OverrideCommandOptions } from '../shared' 3import { AbstractCommand, OverrideCommandOptions } from '../shared'
4 4
5export class DebugCommand extends AbstractCommand { 5export class DebugCommand extends AbstractCommand {
diff --git a/shared/extra-utils/server/follows-command.ts b/shared/extra-utils/server/follows-command.ts
index 4e9ed9494..694f5ea24 100644
--- a/shared/extra-utils/server/follows-command.ts
+++ b/shared/extra-utils/server/follows-command.ts
@@ -1,6 +1,6 @@
1import { pick } from 'lodash' 1import { pick } from 'lodash'
2import { ActivityPubActorType, ActorFollow, FollowState, ResultList } from '@shared/models' 2import { ActivityPubActorType, ActorFollow, FollowState, ResultList } from '@shared/models'
3import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' 3import { HttpStatusCode } from '@shared/models'
4import { AbstractCommand, OverrideCommandOptions } from '../shared' 4import { AbstractCommand, OverrideCommandOptions } from '../shared'
5import { PeerTubeServer } from './server' 5import { PeerTubeServer } from './server'
6 6
diff --git a/shared/extra-utils/server/jobs-command.ts b/shared/extra-utils/server/jobs-command.ts
index 392b868c1..09a299e5b 100644
--- a/shared/extra-utils/server/jobs-command.ts
+++ b/shared/extra-utils/server/jobs-command.ts
@@ -1,5 +1,5 @@
1import { pick } from 'lodash' 1import { pick } from 'lodash'
2import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' 2import { HttpStatusCode } from '@shared/models'
3import { Job, JobState, JobType, ResultList } from '../../models' 3import { Job, JobState, JobType, ResultList } from '../../models'
4import { AbstractCommand, OverrideCommandOptions } from '../shared' 4import { AbstractCommand, OverrideCommandOptions } from '../shared'
5 5
diff --git a/shared/extra-utils/server/plugins-command.ts b/shared/extra-utils/server/plugins-command.ts
index 98049ce19..59bc79b3d 100644
--- a/shared/extra-utils/server/plugins-command.ts
+++ b/shared/extra-utils/server/plugins-command.ts
@@ -3,7 +3,7 @@
3import { readJSON, writeJSON } from 'fs-extra' 3import { readJSON, writeJSON } from 'fs-extra'
4import { join } from 'path' 4import { join } from 'path'
5import { root } from '@server/helpers/core-utils' 5import { root } from '@server/helpers/core-utils'
6import { HttpStatusCode } from '@shared/core-utils' 6import { HttpStatusCode } from '@shared/models'
7import { 7import {
8 PeerTubePlugin, 8 PeerTubePlugin,
9 PeerTubePluginIndex, 9 PeerTubePluginIndex,
diff --git a/shared/extra-utils/server/redundancy-command.ts b/shared/extra-utils/server/redundancy-command.ts
index 728332fdd..137d7f01c 100644
--- a/shared/extra-utils/server/redundancy-command.ts
+++ b/shared/extra-utils/server/redundancy-command.ts
@@ -1,5 +1,5 @@
1import { ResultList, VideoRedundanciesTarget, VideoRedundancy } from '@shared/models' 1import { ResultList, VideoRedundanciesTarget, VideoRedundancy } from '@shared/models'
2import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' 2import { HttpStatusCode } from '@shared/models'
3import { AbstractCommand, OverrideCommandOptions } from '../shared' 3import { AbstractCommand, OverrideCommandOptions } from '../shared'
4 4
5export class RedundancyCommand extends AbstractCommand { 5export class RedundancyCommand extends AbstractCommand {
diff --git a/shared/extra-utils/server/server.ts b/shared/extra-utils/server/server.ts
index cc6df2efe..b33bb9d1e 100644
--- a/shared/extra-utils/server/server.ts
+++ b/shared/extra-utils/server/server.ts
@@ -254,7 +254,7 @@ export class PeerTubeServer {
254 254
255 process.on('exit', () => { 255 process.on('exit', () => {
256 try { 256 try {
257 process.kill(self.server.app.pid) 257 process.kill(self.app.pid)
258 } catch { /* empty */ } 258 } catch { /* empty */ }
259 }) 259 })
260 260
diff --git a/shared/extra-utils/server/servers-command.ts b/shared/extra-utils/server/servers-command.ts
index 1a7b2aade..107e2b4ad 100644
--- a/shared/extra-utils/server/servers-command.ts
+++ b/shared/extra-utils/server/servers-command.ts
@@ -2,7 +2,7 @@ import { exec } from 'child_process'
2import { copy, ensureDir, readFile, remove } from 'fs-extra' 2import { copy, ensureDir, readFile, remove } from 'fs-extra'
3import { join } from 'path' 3import { join } from 'path'
4import { root } from '@server/helpers/core-utils' 4import { root } from '@server/helpers/core-utils'
5import { HttpStatusCode } from '@shared/core-utils' 5import { HttpStatusCode } from '@shared/models'
6import { getFileSize } from '@uploadx/core' 6import { getFileSize } from '@uploadx/core'
7import { isGithubCI, wait } from '../miscs' 7import { isGithubCI, wait } from '../miscs'
8import { AbstractCommand, OverrideCommandOptions } from '../shared' 8import { AbstractCommand, OverrideCommandOptions } from '../shared'
diff --git a/shared/extra-utils/server/stats-command.ts b/shared/extra-utils/server/stats-command.ts
index f0f02ca08..6db473588 100644
--- a/shared/extra-utils/server/stats-command.ts
+++ b/shared/extra-utils/server/stats-command.ts
@@ -1,5 +1,5 @@
1import { ServerStats } from '@shared/models' 1import { ServerStats } from '@shared/models'
2import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' 2import { HttpStatusCode } from '@shared/models'
3import { AbstractCommand, OverrideCommandOptions } from '../shared' 3import { AbstractCommand, OverrideCommandOptions } from '../shared'
4 4
5export class StatsCommand extends AbstractCommand { 5export class StatsCommand extends AbstractCommand {
diff --git a/shared/extra-utils/shared/abstract-command.ts b/shared/extra-utils/shared/abstract-command.ts
index 967f8f2ac..021045e49 100644
--- a/shared/extra-utils/shared/abstract-command.ts
+++ b/shared/extra-utils/shared/abstract-command.ts
@@ -24,15 +24,20 @@ interface InternalCommonCommandOptions extends OverrideCommandOptions {
24 // If we automatically send the server token if the token is not provided 24 // If we automatically send the server token if the token is not provided
25 implicitToken: boolean 25 implicitToken: boolean
26 defaultExpectedStatus: number 26 defaultExpectedStatus: number
27}
28 27
29interface InternalGetCommandOptions extends InternalCommonCommandOptions { 28 // Common optional request parameters
30 query?: { [ id: string ]: any }
31 contentType?: string 29 contentType?: string
32 accept?: string 30 accept?: string
33 redirects?: number 31 redirects?: number
34 range?: string 32 range?: string
35 host?: string 33 host?: string
34 headers?: { [ name: string ]: string }
35 requestType?: string
36 xForwardedFor?: string
37}
38
39interface InternalGetCommandOptions extends InternalCommonCommandOptions {
40 query?: { [ id: string ]: any }
36} 41}
37 42
38abstract class AbstractCommand { 43abstract class AbstractCommand {
@@ -59,7 +64,7 @@ abstract class AbstractCommand {
59 ...options, 64 ...options,
60 65
61 token: this.buildCommonRequestToken(options), 66 token: this.buildCommonRequestToken(options),
62 defaultExpectedStatus: this.buildStatusCodeExpected(options), 67 defaultExpectedStatus: this.buildExpectedStatus(options),
63 68
64 url: `${protocol}//${host}`, 69 url: `${protocol}//${host}`,
65 path: pathname, 70 path: pathname,
@@ -68,17 +73,12 @@ abstract class AbstractCommand {
68 } 73 }
69 74
70 protected getRequest (options: InternalGetCommandOptions) { 75 protected getRequest (options: InternalGetCommandOptions) {
71 const { redirects, query, contentType, accept, range, host } = options 76 const { query } = options
72 77
73 return makeGetRequest({ 78 return makeGetRequest({
74 ...this.buildCommonRequestOptions(options), 79 ...this.buildCommonRequestOptions(options),
75 80
76 redirects, 81 query
77 query,
78 contentType,
79 range,
80 host,
81 accept
82 }) 82 })
83 } 83 }
84 84
@@ -100,51 +100,41 @@ abstract class AbstractCommand {
100 100
101 protected postBodyRequest (options: InternalCommonCommandOptions & { 101 protected postBodyRequest (options: InternalCommonCommandOptions & {
102 fields?: { [ fieldName: string ]: any } 102 fields?: { [ fieldName: string ]: any }
103 headers?: { [ name: string ]: string }
104 type?: string
105 xForwardedFor?: string
106 }) { 103 }) {
107 const { type, fields, xForwardedFor, headers } = options 104 const { fields } = options
108 105
109 return makePostBodyRequest({ 106 return makePostBodyRequest({
110 ...this.buildCommonRequestOptions(options), 107 ...this.buildCommonRequestOptions(options),
111 108
112 fields, 109 fields
113 xForwardedFor,
114 type,
115 headers
116 }) 110 })
117 } 111 }
118 112
119 protected postUploadRequest (options: InternalCommonCommandOptions & { 113 protected postUploadRequest (options: InternalCommonCommandOptions & {
120 fields?: { [ fieldName: string ]: any } 114 fields?: { [ fieldName: string ]: any }
121 attaches?: { [ fieldName: string ]: any } 115 attaches?: { [ fieldName: string ]: any }
122 headers?: { [ name: string ]: string }
123 }) { 116 }) {
124 const { fields, attaches, headers } = options 117 const { fields, attaches } = options
125 118
126 return makeUploadRequest({ 119 return makeUploadRequest({
127 ...this.buildCommonRequestOptions(options), 120 ...this.buildCommonRequestOptions(options),
128 121
129 method: 'POST', 122 method: 'POST',
130 fields, 123 fields,
131 attaches, 124 attaches
132 headers
133 }) 125 })
134 } 126 }
135 127
136 protected putUploadRequest (options: InternalCommonCommandOptions & { 128 protected putUploadRequest (options: InternalCommonCommandOptions & {
137 fields?: { [ fieldName: string ]: any } 129 fields?: { [ fieldName: string ]: any }
138 attaches?: { [ fieldName: string ]: any } 130 attaches?: { [ fieldName: string ]: any }
139 headers?: { [ name: string ]: string }
140 }) { 131 }) {
141 const { fields, attaches, headers } = options 132 const { fields, attaches } = options
142 133
143 return makeUploadRequest({ 134 return makeUploadRequest({
144 ...this.buildCommonRequestOptions(options), 135 ...this.buildCommonRequestOptions(options),
145 136
146 method: 'PUT', 137 method: 'PUT',
147 headers,
148 fields, 138 fields,
149 attaches 139 attaches
150 }) 140 })
@@ -154,12 +144,9 @@ abstract class AbstractCommand {
154 fixture: string 144 fixture: string
155 fieldname: string 145 fieldname: string
156 }) { 146 }) {
157 let filePath = '' 147 const filePath = isAbsolute(options.fixture)
158 if (isAbsolute(options.fixture)) { 148 ? options.fixture
159 filePath = options.fixture 149 : join(root(), 'server', 'tests', 'fixtures', options.fixture)
160 } else {
161 filePath = join(root(), 'server', 'tests', 'fixtures', options.fixture)
162 }
163 150
164 return this.postUploadRequest({ 151 return this.postUploadRequest({
165 ...options, 152 ...options,
@@ -170,14 +157,23 @@ abstract class AbstractCommand {
170 } 157 }
171 158
172 protected buildCommonRequestOptions (options: InternalCommonCommandOptions) { 159 protected buildCommonRequestOptions (options: InternalCommonCommandOptions) {
173 const { url, path } = options 160 const { url, path, redirects, contentType, accept, range, host, headers, requestType, xForwardedFor } = options
174 161
175 return { 162 return {
176 url: url ?? this.server.url, 163 url: url ?? this.server.url,
177 path, 164 path,
178 165
179 token: this.buildCommonRequestToken(options), 166 token: this.buildCommonRequestToken(options),
180 statusCodeExpected: this.buildStatusCodeExpected(options) 167 expectedStatus: this.buildExpectedStatus(options),
168
169 redirects,
170 contentType,
171 range,
172 host,
173 accept,
174 headers,
175 type: requestType,
176 xForwardedFor
181 } 177 }
182 } 178 }
183 179
@@ -191,7 +187,7 @@ abstract class AbstractCommand {
191 return token !== undefined ? token : fallbackToken 187 return token !== undefined ? token : fallbackToken
192 } 188 }
193 189
194 protected buildStatusCodeExpected (options: Pick<InternalCommonCommandOptions, 'expectedStatus' | 'defaultExpectedStatus'>) { 190 protected buildExpectedStatus (options: Pick<InternalCommonCommandOptions, 'expectedStatus' | 'defaultExpectedStatus'>) {
195 const { expectedStatus, defaultExpectedStatus } = options 191 const { expectedStatus, defaultExpectedStatus } = options
196 192
197 return expectedStatus !== undefined ? expectedStatus : defaultExpectedStatus 193 return expectedStatus !== undefined ? expectedStatus : defaultExpectedStatus
diff --git a/shared/extra-utils/users/accounts-command.ts b/shared/extra-utils/users/accounts-command.ts
index 4cd1d2158..08977e58b 100644
--- a/shared/extra-utils/users/accounts-command.ts
+++ b/shared/extra-utils/users/accounts-command.ts
@@ -1,5 +1,5 @@
1import { ResultList } from '@shared/models' 1import { ResultList } from '@shared/models'
2import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' 2import { HttpStatusCode } from '@shared/models'
3import { Account } from '../../models/actors' 3import { Account } from '../../models/actors'
4import { AccountVideoRate, VideoRateType } from '../../models/videos' 4import { AccountVideoRate, VideoRateType } from '../../models/videos'
5import { AbstractCommand, OverrideCommandOptions } from '../shared' 5import { AbstractCommand, OverrideCommandOptions } from '../shared'
diff --git a/shared/extra-utils/users/blocklist-command.ts b/shared/extra-utils/users/blocklist-command.ts
index 089b5a579..a9431acf3 100644
--- a/shared/extra-utils/users/blocklist-command.ts
+++ b/shared/extra-utils/users/blocklist-command.ts
@@ -1,6 +1,6 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import { HttpStatusCode } from '@shared/core-utils' 3import { HttpStatusCode } from '@shared/models'
4import { AccountBlock, ResultList, ServerBlock } from '@shared/models' 4import { AccountBlock, ResultList, ServerBlock } from '@shared/models'
5import { AbstractCommand, OverrideCommandOptions } from '../shared' 5import { AbstractCommand, OverrideCommandOptions } from '../shared'
6 6
diff --git a/shared/extra-utils/users/index.ts b/shared/extra-utils/users/index.ts
index e6107afa5..fbb454e8f 100644
--- a/shared/extra-utils/users/index.ts
+++ b/shared/extra-utils/users/index.ts
@@ -7,4 +7,3 @@ export * from './notifications'
7export * from './notifications-command' 7export * from './notifications-command'
8export * from './subscriptions-command' 8export * from './subscriptions-command'
9export * from './users-command' 9export * from './users-command'
10export * from './users'
diff --git a/shared/extra-utils/users/login-command.ts b/shared/extra-utils/users/login-command.ts
index 10c3db851..b39577260 100644
--- a/shared/extra-utils/users/login-command.ts
+++ b/shared/extra-utils/users/login-command.ts
@@ -1,4 +1,4 @@
1import { HttpStatusCode } from '@shared/core-utils' 1import { HttpStatusCode } from '@shared/models'
2import { PeerTubeProblemDocument } from '@shared/models' 2import { PeerTubeProblemDocument } from '@shared/models'
3import { unwrapBody } from '../requests' 3import { unwrapBody } from '../requests'
4import { AbstractCommand, OverrideCommandOptions } from '../shared' 4import { AbstractCommand, OverrideCommandOptions } from '../shared'
@@ -26,7 +26,7 @@ export class LoginCommand extends AbstractCommand {
26 ...options, 26 ...options,
27 27
28 path, 28 path,
29 type: 'form', 29 requestType: 'form',
30 fields: body, 30 fields: body,
31 implicitToken: false, 31 implicitToken: false,
32 defaultExpectedStatus: HttpStatusCode.OK_200 32 defaultExpectedStatus: HttpStatusCode.OK_200
@@ -72,7 +72,7 @@ export class LoginCommand extends AbstractCommand {
72 ...options, 72 ...options,
73 73
74 path, 74 path,
75 type: 'form', 75 requestType: 'form',
76 fields: body, 76 fields: body,
77 implicitToken: false, 77 implicitToken: false,
78 defaultExpectedStatus: HttpStatusCode.OK_200 78 defaultExpectedStatus: HttpStatusCode.OK_200
@@ -88,7 +88,7 @@ export class LoginCommand extends AbstractCommand {
88 ...options, 88 ...options,
89 89
90 path, 90 path,
91 type: 'form', 91 requestType: 'form',
92 implicitToken: false, 92 implicitToken: false,
93 defaultExpectedStatus: HttpStatusCode.OK_200 93 defaultExpectedStatus: HttpStatusCode.OK_200
94 })) 94 }))
@@ -111,7 +111,7 @@ export class LoginCommand extends AbstractCommand {
111 ...options, 111 ...options,
112 112
113 path, 113 path,
114 type: 'form', 114 requestType: 'form',
115 fields: body, 115 fields: body,
116 implicitToken: false, 116 implicitToken: false,
117 defaultExpectedStatus: HttpStatusCode.OK_200 117 defaultExpectedStatus: HttpStatusCode.OK_200
diff --git a/shared/extra-utils/users/notifications-command.ts b/shared/extra-utils/users/notifications-command.ts
index dfe574ca1..a51fcc3af 100644
--- a/shared/extra-utils/users/notifications-command.ts
+++ b/shared/extra-utils/users/notifications-command.ts
@@ -1,5 +1,5 @@
1import { ResultList } from '@shared/models' 1import { ResultList } from '@shared/models'
2import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' 2import { HttpStatusCode } from '@shared/models'
3import { UserNotification, UserNotificationSetting } from '../../models/users' 3import { UserNotification, UserNotificationSetting } from '../../models/users'
4import { AbstractCommand, OverrideCommandOptions } from '../shared' 4import { AbstractCommand, OverrideCommandOptions } from '../shared'
5 5
diff --git a/shared/extra-utils/users/subscriptions-command.ts b/shared/extra-utils/users/subscriptions-command.ts
index e998eb426..a69d2a194 100644
--- a/shared/extra-utils/users/subscriptions-command.ts
+++ b/shared/extra-utils/users/subscriptions-command.ts
@@ -1,5 +1,5 @@
1import { ResultList, Video, VideoChannel } from '@shared/models' 1import { ResultList, Video, VideoChannel } from '@shared/models'
2import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' 2import { HttpStatusCode } from '@shared/models'
3import { AbstractCommand, OverrideCommandOptions } from '../shared' 3import { AbstractCommand, OverrideCommandOptions } from '../shared'
4 4
5export class SubscriptionsCommand extends AbstractCommand { 5export class SubscriptionsCommand extends AbstractCommand {
diff --git a/shared/extra-utils/users/users-command.ts b/shared/extra-utils/users/users-command.ts
index 59dc6d018..f3a251e65 100644
--- a/shared/extra-utils/users/users-command.ts
+++ b/shared/extra-utils/users/users-command.ts
@@ -1,5 +1,5 @@
1import { omit, pick } from 'lodash' 1import { omit, pick } from 'lodash'
2import { HttpStatusCode } from '@shared/core-utils' 2import { HttpStatusCode } from '@shared/models'
3import { 3import {
4 MyUser, 4 MyUser,
5 ResultList, 5 ResultList,
diff --git a/shared/extra-utils/users/users.ts b/shared/extra-utils/users/users.ts
deleted file mode 100644
index 6cf61d60e..000000000
--- a/shared/extra-utils/users/users.ts
+++ /dev/null
@@ -1,20 +0,0 @@
1import * as request from 'supertest'
2import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
3
4// FIXME: delete once videos does not use it anymore
5function xxxgetMyUserInformation (url: string, accessToken: string, specialStatus = HttpStatusCode.OK_200) {
6 const path = '/api/v1/users/me'
7
8 return request(url)
9 .get(path)
10 .set('Accept', 'application/json')
11 .set('Authorization', 'Bearer ' + accessToken)
12 .expect(specialStatus)
13 .expect('Content-Type', /json/)
14}
15
16// ---------------------------------------------------------------------------
17
18export {
19 xxxgetMyUserInformation
20}
diff --git a/shared/extra-utils/videos/blacklist-command.ts b/shared/extra-utils/videos/blacklist-command.ts
index fdae6b469..9404d4c08 100644
--- a/shared/extra-utils/videos/blacklist-command.ts
+++ b/shared/extra-utils/videos/blacklist-command.ts
@@ -1,6 +1,6 @@
1 1
2import { ResultList } from '@shared/models' 2import { ResultList } from '@shared/models'
3import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' 3import { HttpStatusCode } from '@shared/models'
4import { VideoBlacklist, VideoBlacklistType } from '../../models/videos' 4import { VideoBlacklist, VideoBlacklistType } from '../../models/videos'
5import { AbstractCommand, OverrideCommandOptions } from '../shared' 5import { AbstractCommand, OverrideCommandOptions } from '../shared'
6 6
diff --git a/shared/extra-utils/videos/captions-command.ts b/shared/extra-utils/videos/captions-command.ts
index ac3bde7a9..04dd32f84 100644
--- a/shared/extra-utils/videos/captions-command.ts
+++ b/shared/extra-utils/videos/captions-command.ts
@@ -1,4 +1,4 @@
1import { HttpStatusCode } from '@shared/core-utils' 1import { HttpStatusCode } from '@shared/models'
2import { ResultList, VideoCaption } from '@shared/models' 2import { ResultList, VideoCaption } from '@shared/models'
3import { buildAbsoluteFixturePath } from '../miscs' 3import { buildAbsoluteFixturePath } from '../miscs'
4import { AbstractCommand, OverrideCommandOptions } from '../shared' 4import { AbstractCommand, OverrideCommandOptions } from '../shared'
diff --git a/shared/extra-utils/videos/captions.ts b/shared/extra-utils/videos/captions.ts
index 2246bd133..ff8a43366 100644
--- a/shared/extra-utils/videos/captions.ts
+++ b/shared/extra-utils/videos/captions.ts
@@ -1,6 +1,6 @@
1import { expect } from 'chai' 1import { expect } from 'chai'
2import * as request from 'supertest' 2import * as request from 'supertest'
3import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' 3import { HttpStatusCode } from '@shared/models'
4 4
5async function testCaptionFile (url: string, captionPath: string, containsString: string) { 5async function testCaptionFile (url: string, captionPath: string, containsString: string) {
6 const res = await request(url) 6 const res = await request(url)
diff --git a/shared/extra-utils/videos/change-ownership-command.ts b/shared/extra-utils/videos/change-ownership-command.ts
index 03f77a95f..ef6f07536 100644
--- a/shared/extra-utils/videos/change-ownership-command.ts
+++ b/shared/extra-utils/videos/change-ownership-command.ts
@@ -1,6 +1,6 @@
1 1
2import { ResultList, VideoChangeOwnership } from '@shared/models' 2import { ResultList, VideoChangeOwnership } from '@shared/models'
3import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' 3import { HttpStatusCode } from '@shared/models'
4import { AbstractCommand, OverrideCommandOptions } from '../shared' 4import { AbstractCommand, OverrideCommandOptions } from '../shared'
5 5
6export class ChangeOwnershipCommand extends AbstractCommand { 6export class ChangeOwnershipCommand extends AbstractCommand {
diff --git a/shared/extra-utils/videos/channels-command.ts b/shared/extra-utils/videos/channels-command.ts
index a98c5cc93..e5393ff56 100644
--- a/shared/extra-utils/videos/channels-command.ts
+++ b/shared/extra-utils/videos/channels-command.ts
@@ -1,6 +1,6 @@
1import { pick } from 'lodash' 1import { pick } from 'lodash'
2import { ResultList, VideoChannel, VideoChannelCreateResult } from '@shared/models' 2import { ResultList, VideoChannel, VideoChannelCreateResult } from '@shared/models'
3import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' 3import { HttpStatusCode } from '@shared/models'
4import { VideoChannelCreate } from '../../models/videos/channel/video-channel-create.model' 4import { VideoChannelCreate } from '../../models/videos/channel/video-channel-create.model'
5import { VideoChannelUpdate } from '../../models/videos/channel/video-channel-update.model' 5import { VideoChannelUpdate } from '../../models/videos/channel/video-channel-update.model'
6import { unwrapBody } from '../requests' 6import { unwrapBody } from '../requests'
diff --git a/shared/extra-utils/videos/comments-command.ts b/shared/extra-utils/videos/comments-command.ts
index b31f3e2dd..7368f3ea2 100644
--- a/shared/extra-utils/videos/comments-command.ts
+++ b/shared/extra-utils/videos/comments-command.ts
@@ -1,6 +1,6 @@
1import { pick } from 'lodash' 1import { pick } from 'lodash'
2import { HttpStatusCode } from '@shared/models'
2import { ResultList, VideoComment, VideoCommentThreads, VideoCommentThreadTree } from '@shared/models' 3import { ResultList, VideoComment, VideoCommentThreads, VideoCommentThreadTree } from '@shared/models'
3import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
4import { unwrapBody } from '../requests' 4import { unwrapBody } from '../requests'
5import { AbstractCommand, OverrideCommandOptions } from '../shared' 5import { AbstractCommand, OverrideCommandOptions } from '../shared'
6 6
diff --git a/shared/extra-utils/videos/history-command.ts b/shared/extra-utils/videos/history-command.ts
index 8a144a312..41afc6bc6 100644
--- a/shared/extra-utils/videos/history-command.ts
+++ b/shared/extra-utils/videos/history-command.ts
@@ -1,5 +1,5 @@
1import { HttpStatusCode } from '@shared/models'
1import { ResultList, Video } from '@shared/models' 2import { ResultList, Video } from '@shared/models'
2import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
3import { AbstractCommand, OverrideCommandOptions } from '../shared' 3import { AbstractCommand, OverrideCommandOptions } from '../shared'
4 4
5export class HistoryCommand extends AbstractCommand { 5export class HistoryCommand extends AbstractCommand {
diff --git a/shared/extra-utils/videos/imports-command.ts b/shared/extra-utils/videos/imports-command.ts
index de8b65829..d30f9745b 100644
--- a/shared/extra-utils/videos/imports-command.ts
+++ b/shared/extra-utils/videos/imports-command.ts
@@ -1,6 +1,6 @@
1 1
2import { HttpStatusCode } from '@shared/models'
2import { ResultList } from '@shared/models' 3import { ResultList } from '@shared/models'
3import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
4import { VideoImport, VideoImportCreate } from '../../models/videos' 4import { VideoImport, VideoImportCreate } from '../../models/videos'
5import { unwrapBody } from '../requests' 5import { unwrapBody } from '../requests'
6import { AbstractCommand, OverrideCommandOptions } from '../shared' 6import { AbstractCommand, OverrideCommandOptions } from '../shared'
diff --git a/shared/extra-utils/videos/live-command.ts b/shared/extra-utils/videos/live-command.ts
index fd66c9924..9dfe3087e 100644
--- a/shared/extra-utils/videos/live-command.ts
+++ b/shared/extra-utils/videos/live-command.ts
@@ -3,8 +3,8 @@
3import { readdir } from 'fs-extra' 3import { readdir } from 'fs-extra'
4import { omit } from 'lodash' 4import { omit } from 'lodash'
5import { join } from 'path' 5import { join } from 'path'
6import { HttpStatusCode } from '@shared/models'
6import { LiveVideo, LiveVideoCreate, LiveVideoUpdate, VideoCreateResult, VideoDetails, VideoState } from '@shared/models' 7import { LiveVideo, LiveVideoCreate, LiveVideoUpdate, VideoCreateResult, VideoDetails, VideoState } from '@shared/models'
7import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
8import { wait } from '../miscs' 8import { wait } from '../miscs'
9import { unwrapBody } from '../requests' 9import { unwrapBody } from '../requests'
10import { AbstractCommand, OverrideCommandOptions } from '../shared' 10import { AbstractCommand, OverrideCommandOptions } from '../shared'
diff --git a/shared/extra-utils/videos/playlists-command.ts b/shared/extra-utils/videos/playlists-command.ts
index cbfc7e10f..40162c30d 100644
--- a/shared/extra-utils/videos/playlists-command.ts
+++ b/shared/extra-utils/videos/playlists-command.ts
@@ -1,5 +1,5 @@
1import { omit, pick } from 'lodash' 1import { omit, pick } from 'lodash'
2import { HttpStatusCode } from '@shared/core-utils' 2import { HttpStatusCode } from '@shared/models'
3import { 3import {
4 BooleanBothQuery, 4 BooleanBothQuery,
5 ResultList, 5 ResultList,
diff --git a/shared/extra-utils/videos/services-command.ts b/shared/extra-utils/videos/services-command.ts
index 313b7878c..06760df42 100644
--- a/shared/extra-utils/videos/services-command.ts
+++ b/shared/extra-utils/videos/services-command.ts
@@ -1,4 +1,4 @@
1import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' 1import { HttpStatusCode } from '@shared/models'
2import { AbstractCommand, OverrideCommandOptions } from '../shared' 2import { AbstractCommand, OverrideCommandOptions } from '../shared'
3 3
4export class ServicesCommand extends AbstractCommand { 4export class ServicesCommand extends AbstractCommand {
diff --git a/shared/extra-utils/videos/streaming-playlists-command.ts b/shared/extra-utils/videos/streaming-playlists-command.ts
index fab3eb556..9662685da 100644
--- a/shared/extra-utils/videos/streaming-playlists-command.ts
+++ b/shared/extra-utils/videos/streaming-playlists-command.ts
@@ -1,5 +1,4 @@
1 1import { HttpStatusCode } from '@shared/models'
2import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
3import { unwrapBody, unwrapText } from '../requests' 2import { unwrapBody, unwrapText } from '../requests'
4import { AbstractCommand, OverrideCommandOptions } from '../shared' 3import { AbstractCommand, OverrideCommandOptions } from '../shared'
5 4
diff --git a/shared/extra-utils/videos/streaming-playlists.ts b/shared/extra-utils/videos/streaming-playlists.ts
index 002ae08b2..007d3d98d 100644
--- a/shared/extra-utils/videos/streaming-playlists.ts
+++ b/shared/extra-utils/videos/streaming-playlists.ts
@@ -1,6 +1,6 @@
1import { expect } from 'chai' 1import { expect } from 'chai'
2import { sha256 } from '@server/helpers/core-utils' 2import { sha256 } from '@server/helpers/core-utils'
3import { HttpStatusCode } from '@shared/core-utils' 3import { HttpStatusCode } from '@shared/models'
4import { VideoStreamingPlaylist } from '@shared/models' 4import { VideoStreamingPlaylist } from '@shared/models'
5import { PeerTubeServer } from '../server' 5import { PeerTubeServer } from '../server'
6 6
diff --git a/shared/extra-utils/videos/videos-command.ts b/shared/extra-utils/videos/videos-command.ts
index feef5a771..f46d386f4 100644
--- a/shared/extra-utils/videos/videos-command.ts
+++ b/shared/extra-utils/videos/videos-command.ts
@@ -7,7 +7,7 @@ import { omit, pick } from 'lodash'
7import validator from 'validator' 7import validator from 'validator'
8import { buildUUID } from '@server/helpers/uuid' 8import { buildUUID } from '@server/helpers/uuid'
9import { loadLanguages } from '@server/initializers/constants' 9import { loadLanguages } from '@server/initializers/constants'
10import { HttpStatusCode } from '@shared/core-utils' 10import { HttpStatusCode } from '@shared/models'
11import { 11import {
12 ResultList, 12 ResultList,
13 UserVideoRateType, 13 UserVideoRateType,
@@ -234,10 +234,10 @@ export class VideosCommand extends AbstractCommand {
234 } 234 }
235 235
236 listByAccount (options: OverrideCommandOptions & VideosWithSearchCommonQuery & { 236 listByAccount (options: OverrideCommandOptions & VideosWithSearchCommonQuery & {
237 accountName: string 237 handle: string
238 }) { 238 }) {
239 const { accountName, search } = options 239 const { handle, search } = options
240 const path = '/api/v1/accounts/' + accountName + '/videos' 240 const path = '/api/v1/accounts/' + handle + '/videos'
241 241
242 return this.getRequestBody<ResultList<Video>>({ 242 return this.getRequestBody<ResultList<Video>>({
243 ...options, 243 ...options,
@@ -250,10 +250,10 @@ export class VideosCommand extends AbstractCommand {
250 } 250 }
251 251
252 listByChannel (options: OverrideCommandOptions & VideosWithSearchCommonQuery & { 252 listByChannel (options: OverrideCommandOptions & VideosWithSearchCommonQuery & {
253 videoChannelName: string 253 handle: string
254 }) { 254 }) {
255 const { videoChannelName } = options 255 const { handle } = options
256 const path = '/api/v1/video-channels/' + videoChannelName + '/videos' 256 const path = '/api/v1/video-channels/' + handle + '/videos'
257 257
258 return this.getRequestBody<ResultList<Video>>({ 258 return this.getRequestBody<ResultList<Video>>({
259 ...options, 259 ...options,
@@ -309,13 +309,13 @@ export class VideosCommand extends AbstractCommand {
309 }) { 309 }) {
310 const path = '/api/v1/videos/' + options.id 310 const path = '/api/v1/videos/' + options.id
311 311
312 return this.deleteRequest({ 312 return unwrapBody(this.deleteRequest({
313 ...options, 313 ...options,
314 314
315 path, 315 path,
316 implicitToken: true, 316 implicitToken: true,
317 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 317 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
318 }) 318 }))
319 } 319 }
320 320
321 async removeAll () { 321 async removeAll () {
@@ -396,7 +396,7 @@ export class VideosCommand extends AbstractCommand {
396 396
397 async buildResumeUpload (options: OverrideCommandOptions & { 397 async buildResumeUpload (options: OverrideCommandOptions & {
398 attributes: VideoEdit 398 attributes: VideoEdit
399 }) { 399 }): Promise<VideoCreateResult> {
400 const { attributes, expectedStatus } = options 400 const { attributes, expectedStatus } = options
401 401
402 let size = 0 402 let size = 0
@@ -414,7 +414,8 @@ export class VideosCommand extends AbstractCommand {
414 } 414 }
415 } 415 }
416 416
417 const initializeSessionRes = await this.prepareResumableUpload({ ...options, attributes, size, mimetype }) 417 // Do not check status automatically, we'll check it manually
418 const initializeSessionRes = await this.prepareResumableUpload({ ...options, expectedStatus: null, attributes, size, mimetype })
418 const initStatus = initializeSessionRes.status 419 const initStatus = initializeSessionRes.status
419 420
420 if (videoFilePath && initStatus === HttpStatusCode.CREATED_201) { 421 if (videoFilePath && initStatus === HttpStatusCode.CREATED_201) {
@@ -425,7 +426,7 @@ export class VideosCommand extends AbstractCommand {
425 426
426 const result = await this.sendResumableChunks({ ...options, pathUploadId, videoFilePath, size }) 427 const result = await this.sendResumableChunks({ ...options, pathUploadId, videoFilePath, size })
427 428
428 return result.body.video 429 return result.body?.video || result.body as any
429 } 430 }
430 431
431 const expectedInitStatus = expectedStatus === HttpStatusCode.OK_200 432 const expectedInitStatus = expectedStatus === HttpStatusCode.OK_200
@@ -434,7 +435,7 @@ export class VideosCommand extends AbstractCommand {
434 435
435 expect(initStatus).to.equal(expectedInitStatus) 436 expect(initStatus).to.equal(expectedInitStatus)
436 437
437 return initializeSessionRes.body.video as VideoCreateResult 438 return initializeSessionRes.body.video || initializeSessionRes.body
438 } 439 }
439 440
440 async prepareResumableUpload (options: OverrideCommandOptions & { 441 async prepareResumableUpload (options: OverrideCommandOptions & {
@@ -455,7 +456,10 @@ export class VideosCommand extends AbstractCommand {
455 'X-Upload-Content-Length': size.toString() 456 'X-Upload-Content-Length': size.toString()
456 }, 457 },
457 fields: { filename: attributes.fixture, ...this.buildUploadFields(options.attributes) }, 458 fields: { filename: attributes.fixture, ...this.buildUploadFields(options.attributes) },
459 // Fixture will be sent later
460 attaches: this.buildUploadAttaches(omit(options.attributes, 'fixture')),
458 implicitToken: true, 461 implicitToken: true,
462
459 defaultExpectedStatus: null 463 defaultExpectedStatus: null
460 }) 464 })
461 } 465 }
@@ -539,10 +543,10 @@ export class VideosCommand extends AbstractCommand {
539 543
540 const attributes = { name, additionalParams } 544 const attributes = { name, additionalParams }
541 545
542 if (wait) await waitJobs([ this.server ])
543
544 const result = await this.upload({ ...options, attributes }) 546 const result = await this.upload({ ...options, attributes })
545 547
548 if (wait) await waitJobs([ this.server ])
549
546 return { ...result, name } 550 return { ...result, name }
547 } 551 }
548 552
@@ -566,7 +570,7 @@ export class VideosCommand extends AbstractCommand {
566 } 570 }
567 571
568 private buildUploadFields (attributes: VideoEdit) { 572 private buildUploadFields (attributes: VideoEdit) {
569 return omit(attributes, [ 'thumbnailfile', 'previewfile' ]) 573 return omit(attributes, [ 'fixture', 'thumbnailfile', 'previewfile' ])
570 } 574 }
571 575
572 private buildUploadAttaches (attributes: VideoEdit) { 576 private buildUploadAttaches (attributes: VideoEdit) {
diff --git a/shared/extra-utils/videos/videos.ts b/shared/extra-utils/videos/videos.ts
index b41533808..a96073c56 100644
--- a/shared/extra-utils/videos/videos.ts
+++ b/shared/extra-utils/videos/videos.ts
@@ -4,7 +4,7 @@ import { expect } from 'chai'
4import { pathExists, readdir } from 'fs-extra' 4import { pathExists, readdir } from 'fs-extra'
5import { join } from 'path' 5import { join } from 'path'
6import { getLowercaseExtension } from '@server/helpers/core-utils' 6import { getLowercaseExtension } from '@server/helpers/core-utils'
7import { HttpStatusCode } from '@shared/core-utils' 7import { HttpStatusCode } from '@shared/models'
8import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants' 8import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants'
9import { dateIsValid, testImage, webtorrentAdd } from '../miscs' 9import { dateIsValid, testImage, webtorrentAdd } from '../miscs'
10import { makeRawRequest } from '../requests/requests' 10import { makeRawRequest } from '../requests/requests'
diff --git a/shared/core-utils/miscs/http-error-codes.ts b/shared/models/http/http-error-codes.ts
index b2fbdfc5a..b2fbdfc5a 100644
--- a/shared/core-utils/miscs/http-error-codes.ts
+++ b/shared/models/http/http-error-codes.ts
diff --git a/shared/core-utils/miscs/http-methods.ts b/shared/models/http/http-methods.ts
index 1cfa458b9..1cfa458b9 100644
--- a/shared/core-utils/miscs/http-methods.ts
+++ b/shared/models/http/http-methods.ts
diff --git a/shared/models/http/index.ts b/shared/models/http/index.ts
new file mode 100644
index 000000000..ec991afe0
--- /dev/null
+++ b/shared/models/http/index.ts
@@ -0,0 +1,2 @@
1export * from './http-error-codes'
2export * from './http-methods'
diff --git a/shared/models/index.ts b/shared/models/index.ts
index 5c2bc480e..78723d830 100644
--- a/shared/models/index.ts
+++ b/shared/models/index.ts
@@ -4,6 +4,7 @@ export * from './bulk'
4export * from './common' 4export * from './common'
5export * from './custom-markup' 5export * from './custom-markup'
6export * from './feeds' 6export * from './feeds'
7export * from './http'
7export * from './joinpeertube' 8export * from './joinpeertube'
8export * from './moderation' 9export * from './moderation'
9export * from './overviews' 10export * from './overviews'
diff --git a/shared/models/server/peertube-problem-document.model.ts b/shared/models/server/peertube-problem-document.model.ts
index e391d5aad..8dd96f7a3 100644
--- a/shared/models/server/peertube-problem-document.model.ts
+++ b/shared/models/server/peertube-problem-document.model.ts
@@ -1,4 +1,4 @@
1import { HttpStatusCode } from '../../core-utils' 1import { HttpStatusCode } from '../../models'
2import { OAuth2ErrorCode, ServerErrorCode } from './server-error-code.enum' 2import { OAuth2ErrorCode, ServerErrorCode } from './server-error-code.enum'
3 3
4export interface PeerTubeProblemDocumentData { 4export interface PeerTubeProblemDocumentData {