diff options
Diffstat (limited to 'server/middlewares')
47 files changed, 447 insertions, 102 deletions
diff --git a/server/middlewares/activitypub.ts b/server/middlewares/activitypub.ts index 6b43b7764..6ef90b275 100644 --- a/server/middlewares/activitypub.ts +++ b/server/middlewares/activitypub.ts | |||
@@ -2,7 +2,7 @@ import { NextFunction, Request, Response } from 'express' | |||
2 | import { getAPId } from '@server/helpers/activitypub' | 2 | import { getAPId } from '@server/helpers/activitypub' |
3 | import { isActorDeleteActivityValid } from '@server/helpers/custom-validators/activitypub/actor' | 3 | import { isActorDeleteActivityValid } from '@server/helpers/custom-validators/activitypub/actor' |
4 | import { ActivityDelete, ActivityPubSignature } from '../../shared' | 4 | import { ActivityDelete, ActivityPubSignature } from '../../shared' |
5 | import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes' | 5 | import { HttpStatusCode } from '../../shared/models/http/http-error-codes' |
6 | import { logger } from '../helpers/logger' | 6 | import { logger } from '../helpers/logger' |
7 | import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../helpers/peertube-crypto' | 7 | import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../helpers/peertube-crypto' |
8 | import { ACCEPT_HEADERS, ACTIVITY_PUB, HTTP_SIGNATURE } from '../initializers/constants' | 8 | import { ACCEPT_HEADERS, ACTIVITY_PUB, HTTP_SIGNATURE } from '../initializers/constants' |
diff --git a/server/middlewares/auth.ts b/server/middlewares/auth.ts index 176461cc2..9e6327b23 100644 --- a/server/middlewares/auth.ts +++ b/server/middlewares/auth.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { Socket } from 'socket.io' | 2 | import { Socket } from 'socket.io' |
3 | import { getAccessToken } from '@server/lib/auth/oauth-model' | 3 | import { getAccessToken } from '@server/lib/auth/oauth-model' |
4 | import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes' | 4 | import { HttpStatusCode } from '../../shared/models/http/http-error-codes' |
5 | import { logger } from '../helpers/logger' | 5 | import { logger } from '../helpers/logger' |
6 | import { handleOAuthAuthenticate } from '../lib/auth/oauth' | 6 | import { handleOAuthAuthenticate } from '../lib/auth/oauth' |
7 | 7 | ||
diff --git a/server/middlewares/cache.ts b/server/middlewares/cache.ts deleted file mode 100644 index 0708ee8e8..000000000 --- a/server/middlewares/cache.ts +++ /dev/null | |||
@@ -1,28 +0,0 @@ | |||
1 | import { Redis } from '../lib/redis' | ||
2 | import * as apicache from 'apicache' | ||
3 | import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes' | ||
4 | |||
5 | // Ensure Redis is initialized | ||
6 | Redis.Instance.init() | ||
7 | |||
8 | const defaultOptions = { | ||
9 | redisClient: Redis.Instance.getClient(), | ||
10 | appendKey: () => Redis.Instance.getPrefix(), | ||
11 | statusCodes: { | ||
12 | exclude: [ | ||
13 | HttpStatusCode.FORBIDDEN_403, | ||
14 | HttpStatusCode.NOT_FOUND_404 | ||
15 | ] | ||
16 | } | ||
17 | } | ||
18 | |||
19 | const cacheRoute = (extraOptions = {}) => apicache.options({ | ||
20 | ...defaultOptions, | ||
21 | ...extraOptions | ||
22 | }).middleware | ||
23 | |||
24 | // --------------------------------------------------------------------------- | ||
25 | |||
26 | export { | ||
27 | cacheRoute | ||
28 | } | ||
diff --git a/server/middlewares/cache/cache.ts b/server/middlewares/cache/cache.ts new file mode 100644 index 000000000..48162a0ae --- /dev/null +++ b/server/middlewares/cache/cache.ts | |||
@@ -0,0 +1,32 @@ | |||
1 | import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' | ||
2 | import { Redis } from '../../lib/redis' | ||
3 | import { ApiCache, APICacheOptions } from './shared' | ||
4 | |||
5 | // Ensure Redis is initialized | ||
6 | Redis.Instance.init() | ||
7 | |||
8 | const defaultOptions: APICacheOptions = { | ||
9 | excludeStatus: [ | ||
10 | HttpStatusCode.FORBIDDEN_403, | ||
11 | HttpStatusCode.NOT_FOUND_404 | ||
12 | ] | ||
13 | } | ||
14 | |||
15 | function cacheRoute (duration: string) { | ||
16 | const instance = new ApiCache(defaultOptions) | ||
17 | |||
18 | return instance.buildMiddleware(duration) | ||
19 | } | ||
20 | |||
21 | function cacheRouteFactory (options: APICacheOptions) { | ||
22 | const instance = new ApiCache({ ...defaultOptions, ...options }) | ||
23 | |||
24 | return instance.buildMiddleware.bind(instance) | ||
25 | } | ||
26 | |||
27 | // --------------------------------------------------------------------------- | ||
28 | |||
29 | export { | ||
30 | cacheRoute, | ||
31 | cacheRouteFactory | ||
32 | } | ||
diff --git a/server/middlewares/cache/index.ts b/server/middlewares/cache/index.ts new file mode 100644 index 000000000..79b512828 --- /dev/null +++ b/server/middlewares/cache/index.ts | |||
@@ -0,0 +1 @@ | |||
export * from './cache' | |||
diff --git a/server/middlewares/cache/shared/api-cache.ts b/server/middlewares/cache/shared/api-cache.ts new file mode 100644 index 000000000..f9f7b1b67 --- /dev/null +++ b/server/middlewares/cache/shared/api-cache.ts | |||
@@ -0,0 +1,269 @@ | |||
1 | // Thanks: https://github.com/kwhitley/apicache | ||
2 | // We duplicated the library because it is unmaintened and prevent us to upgrade to recent NodeJS versions | ||
3 | |||
4 | import * as express from 'express' | ||
5 | import { OutgoingHttpHeaders } from 'http' | ||
6 | import { isTestInstance, parseDurationToMs } from '@server/helpers/core-utils' | ||
7 | import { logger } from '@server/helpers/logger' | ||
8 | import { Redis } from '@server/lib/redis' | ||
9 | import { HttpStatusCode } from '@shared/models' | ||
10 | |||
11 | export interface APICacheOptions { | ||
12 | headerBlacklist?: string[] | ||
13 | excludeStatus?: HttpStatusCode[] | ||
14 | } | ||
15 | |||
16 | interface CacheObject { | ||
17 | status: number | ||
18 | headers: OutgoingHttpHeaders | ||
19 | data: any | ||
20 | encoding: BufferEncoding | ||
21 | timestamp: number | ||
22 | } | ||
23 | |||
24 | export class ApiCache { | ||
25 | |||
26 | private readonly options: APICacheOptions | ||
27 | private readonly timers: { [ id: string ]: NodeJS.Timeout } = {} | ||
28 | |||
29 | private index: { all: string[] } = { all: [] } | ||
30 | |||
31 | constructor (options: APICacheOptions) { | ||
32 | this.options = { | ||
33 | headerBlacklist: [], | ||
34 | excludeStatus: [], | ||
35 | |||
36 | ...options | ||
37 | } | ||
38 | } | ||
39 | |||
40 | buildMiddleware (strDuration: string) { | ||
41 | const duration = parseDurationToMs(strDuration) | ||
42 | |||
43 | return (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
44 | const key = Redis.Instance.getPrefix() + 'api-cache-' + req.originalUrl | ||
45 | const redis = Redis.Instance.getClient() | ||
46 | |||
47 | if (!redis.connected) return this.makeResponseCacheable(res, next, key, duration) | ||
48 | |||
49 | try { | ||
50 | redis.hgetall(key, (err, obj) => { | ||
51 | if (!err && obj && obj.response) { | ||
52 | return this.sendCachedResponse(req, res, JSON.parse(obj.response), duration) | ||
53 | } | ||
54 | |||
55 | return this.makeResponseCacheable(res, next, key, duration) | ||
56 | }) | ||
57 | } catch (err) { | ||
58 | return this.makeResponseCacheable(res, next, key, duration) | ||
59 | } | ||
60 | } | ||
61 | } | ||
62 | |||
63 | private shouldCacheResponse (response: express.Response) { | ||
64 | if (!response) return false | ||
65 | if (this.options.excludeStatus.includes(response.statusCode)) return false | ||
66 | |||
67 | return true | ||
68 | } | ||
69 | |||
70 | private addIndexEntries (key: string) { | ||
71 | this.index.all.unshift(key) | ||
72 | } | ||
73 | |||
74 | private filterBlacklistedHeaders (headers: OutgoingHttpHeaders) { | ||
75 | return Object.keys(headers) | ||
76 | .filter(key => !this.options.headerBlacklist.includes(key)) | ||
77 | .reduce((acc, header) => { | ||
78 | acc[header] = headers[header] | ||
79 | |||
80 | return acc | ||
81 | }, {}) | ||
82 | } | ||
83 | |||
84 | private createCacheObject (status: number, headers: OutgoingHttpHeaders, data: any, encoding: BufferEncoding) { | ||
85 | return { | ||
86 | status, | ||
87 | headers: this.filterBlacklistedHeaders(headers), | ||
88 | data, | ||
89 | encoding, | ||
90 | |||
91 | // Seconds since epoch, used to properly decrement max-age headers in cached responses. | ||
92 | timestamp: new Date().getTime() / 1000 | ||
93 | } as CacheObject | ||
94 | } | ||
95 | |||
96 | private cacheResponse (key: string, value: object, duration: number) { | ||
97 | const redis = Redis.Instance.getClient() | ||
98 | |||
99 | if (redis.connected) { | ||
100 | try { | ||
101 | redis.hset(key, 'response', JSON.stringify(value)) | ||
102 | redis.hset(key, 'duration', duration + '') | ||
103 | redis.expire(key, duration / 1000) | ||
104 | } catch (err) { | ||
105 | logger.error('Cannot set cache in redis.', { err }) | ||
106 | } | ||
107 | } | ||
108 | |||
109 | // add automatic cache clearing from duration, includes max limit on setTimeout | ||
110 | this.timers[key] = setTimeout(() => this.clear(key), Math.min(duration, 2147483647)) | ||
111 | } | ||
112 | |||
113 | private accumulateContent (res: express.Response, content: any) { | ||
114 | if (!content) return | ||
115 | |||
116 | if (typeof content === 'string') { | ||
117 | res.locals.apicache.content = (res.locals.apicache.content || '') + content | ||
118 | return | ||
119 | } | ||
120 | |||
121 | if (Buffer.isBuffer(content)) { | ||
122 | let oldContent = res.locals.apicache.content | ||
123 | |||
124 | if (typeof oldContent === 'string') { | ||
125 | oldContent = Buffer.from(oldContent) | ||
126 | } | ||
127 | |||
128 | if (!oldContent) { | ||
129 | oldContent = Buffer.alloc(0) | ||
130 | } | ||
131 | |||
132 | res.locals.apicache.content = Buffer.concat( | ||
133 | [ oldContent, content ], | ||
134 | oldContent.length + content.length | ||
135 | ) | ||
136 | |||
137 | return | ||
138 | } | ||
139 | |||
140 | res.locals.apicache.content = content | ||
141 | } | ||
142 | |||
143 | private makeResponseCacheable (res: express.Response, next: express.NextFunction, key: string, duration: number) { | ||
144 | const self = this | ||
145 | |||
146 | res.locals.apicache = { | ||
147 | write: res.write, | ||
148 | writeHead: res.writeHead, | ||
149 | end: res.end, | ||
150 | cacheable: true, | ||
151 | content: undefined, | ||
152 | headers: {} | ||
153 | } | ||
154 | |||
155 | // Patch express | ||
156 | res.writeHead = function () { | ||
157 | if (self.shouldCacheResponse(res)) { | ||
158 | res.setHeader('cache-control', 'max-age=' + (duration / 1000).toFixed(0)) | ||
159 | } else { | ||
160 | res.setHeader('cache-control', 'no-cache, no-store, must-revalidate') | ||
161 | } | ||
162 | |||
163 | res.locals.apicache.headers = Object.assign({}, res.getHeaders()) | ||
164 | return res.locals.apicache.writeHead.apply(this, arguments as any) | ||
165 | } | ||
166 | |||
167 | res.write = function (chunk: any) { | ||
168 | self.accumulateContent(res, chunk) | ||
169 | return res.locals.apicache.write.apply(this, arguments as any) | ||
170 | } | ||
171 | |||
172 | res.end = function (content: any, encoding: BufferEncoding) { | ||
173 | if (self.shouldCacheResponse(res)) { | ||
174 | self.accumulateContent(res, content) | ||
175 | |||
176 | if (res.locals.apicache.cacheable && res.locals.apicache.content) { | ||
177 | self.addIndexEntries(key) | ||
178 | |||
179 | const headers = res.locals.apicache.headers || res.getHeaders() | ||
180 | const cacheObject = self.createCacheObject( | ||
181 | res.statusCode, | ||
182 | headers, | ||
183 | res.locals.apicache.content, | ||
184 | encoding | ||
185 | ) | ||
186 | self.cacheResponse(key, cacheObject, duration) | ||
187 | } | ||
188 | } | ||
189 | |||
190 | res.locals.apicache.end.apply(this, arguments as any) | ||
191 | } as any | ||
192 | |||
193 | next() | ||
194 | } | ||
195 | |||
196 | private sendCachedResponse (request: express.Request, response: express.Response, cacheObject: CacheObject, duration: number) { | ||
197 | const headers = response.getHeaders() | ||
198 | |||
199 | if (isTestInstance()) { | ||
200 | Object.assign(headers, { | ||
201 | 'x-api-cache-cached': 'true' | ||
202 | }) | ||
203 | } | ||
204 | |||
205 | Object.assign(headers, this.filterBlacklistedHeaders(cacheObject.headers || {}), { | ||
206 | // Set properly decremented max-age header | ||
207 | // This ensures that max-age is in sync with the cache expiration | ||
208 | 'cache-control': | ||
209 | 'max-age=' + | ||
210 | Math.max( | ||
211 | 0, | ||
212 | (duration / 1000 - (new Date().getTime() / 1000 - cacheObject.timestamp)) | ||
213 | ).toFixed(0) | ||
214 | }) | ||
215 | |||
216 | // unstringify buffers | ||
217 | let data = cacheObject.data | ||
218 | if (data && data.type === 'Buffer') { | ||
219 | data = typeof data.data === 'number' | ||
220 | ? Buffer.alloc(data.data) | ||
221 | : Buffer.from(data.data) | ||
222 | } | ||
223 | |||
224 | // Test Etag against If-None-Match for 304 | ||
225 | const cachedEtag = cacheObject.headers.etag | ||
226 | const requestEtag = request.headers['if-none-match'] | ||
227 | |||
228 | if (requestEtag && cachedEtag === requestEtag) { | ||
229 | response.writeHead(304, headers) | ||
230 | return response.end() | ||
231 | } | ||
232 | |||
233 | response.writeHead(cacheObject.status || 200, headers) | ||
234 | |||
235 | return response.end(data, cacheObject.encoding) | ||
236 | } | ||
237 | |||
238 | private clear (target: string) { | ||
239 | const redis = Redis.Instance.getClient() | ||
240 | |||
241 | if (target) { | ||
242 | clearTimeout(this.timers[target]) | ||
243 | delete this.timers[target] | ||
244 | |||
245 | try { | ||
246 | redis.del(target) | ||
247 | } catch (err) { | ||
248 | logger.error('Cannot delete %s in redis cache.', target, { err }) | ||
249 | } | ||
250 | |||
251 | this.index.all = this.index.all.filter(key => key !== target) | ||
252 | } else { | ||
253 | for (const key of this.index.all) { | ||
254 | clearTimeout(this.timers[key]) | ||
255 | delete this.timers[key] | ||
256 | |||
257 | try { | ||
258 | redis.del(key) | ||
259 | } catch (err) { | ||
260 | logger.error('Cannot delete %s in redis cache.', key, { err }) | ||
261 | } | ||
262 | } | ||
263 | |||
264 | this.index.all = [] | ||
265 | } | ||
266 | |||
267 | return this.index | ||
268 | } | ||
269 | } | ||
diff --git a/server/middlewares/cache/shared/index.ts b/server/middlewares/cache/shared/index.ts new file mode 100644 index 000000000..c707eaf7a --- /dev/null +++ b/server/middlewares/cache/shared/index.ts | |||
@@ -0,0 +1 @@ | |||
export * from './api-cache' | |||
diff --git a/server/middlewares/error.ts b/server/middlewares/error.ts index e3eb1c8f5..af5a9c29a 100644 --- a/server/middlewares/error.ts +++ b/server/middlewares/error.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { ProblemDocument, ProblemDocumentExtension } from 'http-problem-details' | 2 | import { ProblemDocument, ProblemDocumentExtension } from 'http-problem-details' |
3 | import { HttpStatusCode } from '@shared/core-utils' | 3 | import { HttpStatusCode } from '@shared/models' |
4 | 4 | ||
5 | function apiFailMiddleware (req: express.Request, res: express.Response, next: express.NextFunction) { | 5 | function apiFailMiddleware (req: express.Request, res: express.Response, next: express.NextFunction) { |
6 | res.fail = options => { | 6 | res.fail = options => { |
diff --git a/server/middlewares/index.ts b/server/middlewares/index.ts index 413653dac..a0035f623 100644 --- a/server/middlewares/index.ts +++ b/server/middlewares/index.ts | |||
@@ -1,4 +1,5 @@ | |||
1 | export * from './validators' | 1 | export * from './validators' |
2 | export * from './cache' | ||
2 | export * from './activitypub' | 3 | export * from './activitypub' |
3 | export * from './async' | 4 | export * from './async' |
4 | export * from './auth' | 5 | export * from './auth' |
diff --git a/server/middlewares/servers.ts b/server/middlewares/servers.ts index 9aa56bc93..cf70d901e 100644 --- a/server/middlewares/servers.ts +++ b/server/middlewares/servers.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { HttpStatusCode } from '../../shared/models/http/http-error-codes' | ||
2 | import { getHostWithPort } from '../helpers/express-utils' | 3 | import { getHostWithPort } from '../helpers/express-utils' |
3 | import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes' | ||
4 | 4 | ||
5 | function setBodyHostsPort (req: express.Request, res: express.Response, next: express.NextFunction) { | 5 | function setBodyHostsPort (req: express.Request, res: express.Response, next: express.NextFunction) { |
6 | if (!req.body.hosts) return next() | 6 | if (!req.body.hosts) return next() |
diff --git a/server/middlewares/user-right.ts b/server/middlewares/user-right.ts index d1888c2d3..c8c694f05 100644 --- a/server/middlewares/user-right.ts +++ b/server/middlewares/user-right.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { UserRight } from '../../shared' | 2 | import { UserRight } from '../../shared' |
3 | import { HttpStatusCode } from '../../shared/models/http/http-error-codes' | ||
3 | import { logger } from '../helpers/logger' | 4 | import { logger } from '../helpers/logger' |
4 | import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes' | ||
5 | 5 | ||
6 | function ensureUserHasRight (userRight: UserRight) { | 6 | function ensureUserHasRight (userRight: UserRight) { |
7 | return function (req: express.Request, res: express.Response, next: express.NextFunction) { | 7 | return function (req: express.Request, res: express.Response, next: express.NextFunction) { |
diff --git a/server/middlewares/validators/abuse.ts b/server/middlewares/validators/abuse.ts index c048bc6af..f4d9c3af2 100644 --- a/server/middlewares/validators/abuse.ts +++ b/server/middlewares/validators/abuse.ts | |||
@@ -16,7 +16,7 @@ import { exists, isIdOrUUIDValid, isIdValid, toCompleteUUID, toIntOrNull } from | |||
16 | import { logger } from '@server/helpers/logger' | 16 | import { logger } from '@server/helpers/logger' |
17 | import { AbuseMessageModel } from '@server/models/abuse/abuse-message' | 17 | import { AbuseMessageModel } from '@server/models/abuse/abuse-message' |
18 | import { AbuseCreate, UserRight } from '@shared/models' | 18 | import { AbuseCreate, UserRight } from '@shared/models' |
19 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 19 | import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' |
20 | import { areValidationErrors, doesAbuseExist, doesAccountIdExist, doesCommentIdExist, doesVideoExist } from './shared' | 20 | import { areValidationErrors, doesAbuseExist, doesAccountIdExist, doesCommentIdExist, doesVideoExist } from './shared' |
21 | 21 | ||
22 | const abuseReportValidator = [ | 22 | const abuseReportValidator = [ |
diff --git a/server/middlewares/validators/activitypub/activity.ts b/server/middlewares/validators/activitypub/activity.ts index cc6acd4b1..d24e4427b 100644 --- a/server/middlewares/validators/activitypub/activity.ts +++ b/server/middlewares/validators/activitypub/activity.ts | |||
@@ -1,8 +1,8 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { getServerActor } from '@server/models/application/application' | ||
3 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' | ||
2 | import { isRootActivityValid } from '../../../helpers/custom-validators/activitypub/activity' | 4 | import { isRootActivityValid } from '../../../helpers/custom-validators/activitypub/activity' |
3 | import { logger } from '../../../helpers/logger' | 5 | import { logger } from '../../../helpers/logger' |
4 | import { getServerActor } from '@server/models/application/application' | ||
5 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
6 | 6 | ||
7 | async function activityPubValidator (req: express.Request, res: express.Response, next: express.NextFunction) { | 7 | async function activityPubValidator (req: express.Request, res: express.Response, next: express.NextFunction) { |
8 | logger.debug('Checking activity pub parameters') | 8 | logger.debug('Checking activity pub parameters') |
diff --git a/server/middlewares/validators/blocklist.ts b/server/middlewares/validators/blocklist.ts index 826b16fc8..f15b293e9 100644 --- a/server/middlewares/validators/blocklist.ts +++ b/server/middlewares/validators/blocklist.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param } from 'express-validator' | 2 | import { body, param } from 'express-validator' |
3 | import { getServerActor } from '@server/models/application/application' | 3 | import { getServerActor } from '@server/models/application/application' |
4 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 4 | import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' |
5 | import { isHostValid } from '../../helpers/custom-validators/servers' | 5 | import { isHostValid } from '../../helpers/custom-validators/servers' |
6 | import { logger } from '../../helpers/logger' | 6 | import { logger } from '../../helpers/logger' |
7 | import { WEBSERVER } from '../../initializers/constants' | 7 | import { WEBSERVER } from '../../initializers/constants' |
diff --git a/server/middlewares/validators/bulk.ts b/server/middlewares/validators/bulk.ts index 9bb95f5b7..6fec58149 100644 --- a/server/middlewares/validators/bulk.ts +++ b/server/middlewares/validators/bulk.ts | |||
@@ -1,8 +1,7 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body } from 'express-validator' | 2 | import { body } from 'express-validator' |
3 | import { isBulkRemoveCommentsOfScopeValid } from '@server/helpers/custom-validators/bulk' | 3 | import { isBulkRemoveCommentsOfScopeValid } from '@server/helpers/custom-validators/bulk' |
4 | import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' | 4 | import { HttpStatusCode, UserRight } from '@shared/models' |
5 | import { UserRight } from '@shared/models' | ||
6 | import { BulkRemoveCommentsOfBody } from '@shared/models/bulk/bulk-remove-comments-of-body.model' | 5 | import { BulkRemoveCommentsOfBody } from '@shared/models/bulk/bulk-remove-comments-of-body.model' |
7 | import { logger } from '../../helpers/logger' | 6 | import { logger } from '../../helpers/logger' |
8 | import { areValidationErrors, doesAccountNameWithHostExist } from './shared' | 7 | import { areValidationErrors, doesAccountNameWithHostExist } from './shared' |
diff --git a/server/middlewares/validators/feeds.ts b/server/middlewares/validators/feeds.ts index 51b8fdd19..d29bebf64 100644 --- a/server/middlewares/validators/feeds.ts +++ b/server/middlewares/validators/feeds.ts | |||
@@ -1,7 +1,6 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { param, query } from 'express-validator' | 2 | import { param, query } from 'express-validator' |
3 | 3 | import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' | |
4 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
5 | import { isValidRSSFeed } from '../../helpers/custom-validators/feeds' | 4 | import { isValidRSSFeed } from '../../helpers/custom-validators/feeds' |
6 | import { exists, isIdOrUUIDValid, isIdValid, toCompleteUUID } from '../../helpers/custom-validators/misc' | 5 | import { exists, isIdOrUUIDValid, isIdValid, toCompleteUUID } from '../../helpers/custom-validators/misc' |
7 | import { logger } from '../../helpers/logger' | 6 | import { logger } from '../../helpers/logger' |
diff --git a/server/middlewares/validators/follows.ts b/server/middlewares/validators/follows.ts index 205baca48..16abdd096 100644 --- a/server/middlewares/validators/follows.ts +++ b/server/middlewares/validators/follows.ts | |||
@@ -1,18 +1,20 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param, query } from 'express-validator' | 2 | import { body, param, query } from 'express-validator' |
3 | import { isFollowStateValid } from '@server/helpers/custom-validators/follows' | 3 | import { isEachUniqueHandleValid, isFollowStateValid, isRemoteHandleValid } from '@server/helpers/custom-validators/follows' |
4 | import { loadActorUrlOrGetFromWebfinger } from '@server/lib/activitypub/actors' | 4 | import { loadActorUrlOrGetFromWebfinger } from '@server/lib/activitypub/actors' |
5 | import { getRemoteNameAndHost } from '@server/lib/activitypub/follow' | ||
5 | import { getServerActor } from '@server/models/application/application' | 6 | import { getServerActor } from '@server/models/application/application' |
6 | import { MActorFollowActorsDefault } from '@server/types/models' | 7 | import { MActorFollowActorsDefault } from '@server/types/models' |
7 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 8 | import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' |
8 | import { isTestInstance } from '../../helpers/core-utils' | 9 | import { isTestInstance } from '../../helpers/core-utils' |
9 | import { isActorTypeValid, isValidActorHandle } from '../../helpers/custom-validators/activitypub/actor' | 10 | import { isActorTypeValid, isValidActorHandle } from '../../helpers/custom-validators/activitypub/actor' |
10 | import { isEachUniqueHostValid, isHostValid } from '../../helpers/custom-validators/servers' | 11 | import { isEachUniqueHostValid, isHostValid } from '../../helpers/custom-validators/servers' |
11 | import { logger } from '../../helpers/logger' | 12 | import { logger } from '../../helpers/logger' |
12 | import { SERVER_ACTOR_NAME, WEBSERVER } from '../../initializers/constants' | 13 | import { WEBSERVER } from '../../initializers/constants' |
13 | import { ActorModel } from '../../models/actor/actor' | 14 | import { ActorModel } from '../../models/actor/actor' |
14 | import { ActorFollowModel } from '../../models/actor/actor-follow' | 15 | import { ActorFollowModel } from '../../models/actor/actor-follow' |
15 | import { areValidationErrors } from './shared' | 16 | import { areValidationErrors } from './shared' |
17 | import { ServerFollowCreate } from '@shared/models' | ||
16 | 18 | ||
17 | const listFollowsValidator = [ | 19 | const listFollowsValidator = [ |
18 | query('state') | 20 | query('state') |
@@ -30,29 +32,46 @@ const listFollowsValidator = [ | |||
30 | ] | 32 | ] |
31 | 33 | ||
32 | const followValidator = [ | 34 | const followValidator = [ |
33 | body('hosts').custom(isEachUniqueHostValid).withMessage('Should have an array of unique hosts'), | 35 | body('hosts') |
36 | .toArray() | ||
37 | .custom(isEachUniqueHostValid).withMessage('Should have an array of unique hosts'), | ||
38 | |||
39 | body('handles') | ||
40 | .toArray() | ||
41 | .custom(isEachUniqueHandleValid).withMessage('Should have an array of handles'), | ||
34 | 42 | ||
35 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 43 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
36 | // Force https if the administrator wants to make friends | 44 | // Force https if the administrator wants to follow remote actors |
37 | if (isTestInstance() === false && WEBSERVER.SCHEME === 'http') { | 45 | if (isTestInstance() === false && WEBSERVER.SCHEME === 'http') { |
38 | return res | 46 | return res |
39 | .status(HttpStatusCode.INTERNAL_SERVER_ERROR_500) | 47 | .status(HttpStatusCode.INTERNAL_SERVER_ERROR_500) |
40 | .json({ | 48 | .json({ |
41 | error: 'Cannot follow on a non HTTPS web server.' | 49 | error: 'Cannot follow on a non HTTPS web server.' |
42 | }) | 50 | }) |
43 | .end() | ||
44 | } | 51 | } |
45 | 52 | ||
46 | logger.debug('Checking follow parameters', { parameters: req.body }) | 53 | logger.debug('Checking follow parameters', { parameters: req.body }) |
47 | 54 | ||
48 | if (areValidationErrors(req, res)) return | 55 | if (areValidationErrors(req, res)) return |
49 | 56 | ||
57 | const body: ServerFollowCreate = req.body | ||
58 | if (body.hosts.length === 0 && body.handles.length === 0) { | ||
59 | |||
60 | return res | ||
61 | .status(HttpStatusCode.BAD_REQUEST_400) | ||
62 | .json({ | ||
63 | error: 'You must provide at least one handle or one host.' | ||
64 | }) | ||
65 | } | ||
66 | |||
50 | return next() | 67 | return next() |
51 | } | 68 | } |
52 | ] | 69 | ] |
53 | 70 | ||
54 | const removeFollowingValidator = [ | 71 | const removeFollowingValidator = [ |
55 | param('host').custom(isHostValid).withMessage('Should have a valid host'), | 72 | param('hostOrHandle') |
73 | .custom(value => isHostValid(value) || isRemoteHandleValid(value)) | ||
74 | .withMessage('Should have a valid host/handle'), | ||
56 | 75 | ||
57 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 76 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
58 | logger.debug('Checking unfollowing parameters', { parameters: req.params }) | 77 | logger.debug('Checking unfollowing parameters', { parameters: req.params }) |
@@ -60,12 +79,14 @@ const removeFollowingValidator = [ | |||
60 | if (areValidationErrors(req, res)) return | 79 | if (areValidationErrors(req, res)) return |
61 | 80 | ||
62 | const serverActor = await getServerActor() | 81 | const serverActor = await getServerActor() |
63 | const follow = await ActorFollowModel.loadByActorAndTargetNameAndHostForAPI(serverActor.id, SERVER_ACTOR_NAME, req.params.host) | 82 | |
83 | const { name, host } = getRemoteNameAndHost(req.params.hostOrHandle) | ||
84 | const follow = await ActorFollowModel.loadByActorAndTargetNameAndHostForAPI(serverActor.id, name, host) | ||
64 | 85 | ||
65 | if (!follow) { | 86 | if (!follow) { |
66 | return res.fail({ | 87 | return res.fail({ |
67 | status: HttpStatusCode.NOT_FOUND_404, | 88 | status: HttpStatusCode.NOT_FOUND_404, |
68 | message: `Following ${req.params.host} not found.` | 89 | message: `Follow ${req.params.hostOrHandle} not found.` |
69 | }) | 90 | }) |
70 | } | 91 | } |
71 | 92 | ||
diff --git a/server/middlewares/validators/oembed.ts b/server/middlewares/validators/oembed.ts index 0a82e6932..e5fc0c277 100644 --- a/server/middlewares/validators/oembed.ts +++ b/server/middlewares/validators/oembed.ts | |||
@@ -4,7 +4,7 @@ import { join } from 'path' | |||
4 | import { loadVideo } from '@server/lib/model-loaders' | 4 | import { loadVideo } from '@server/lib/model-loaders' |
5 | import { VideoPlaylistModel } from '@server/models/video/video-playlist' | 5 | import { VideoPlaylistModel } from '@server/models/video/video-playlist' |
6 | import { VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' | 6 | import { VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' |
7 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 7 | import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' |
8 | import { isTestInstance } from '../../helpers/core-utils' | 8 | import { isTestInstance } from '../../helpers/core-utils' |
9 | import { isIdOrUUIDValid, toCompleteUUID } from '../../helpers/custom-validators/misc' | 9 | import { isIdOrUUIDValid, toCompleteUUID } from '../../helpers/custom-validators/misc' |
10 | import { logger } from '../../helpers/logger' | 10 | import { logger } from '../../helpers/logger' |
diff --git a/server/middlewares/validators/plugins.ts b/server/middlewares/validators/plugins.ts index 8c76d2e36..3fb2176b9 100644 --- a/server/middlewares/validators/plugins.ts +++ b/server/middlewares/validators/plugins.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param, query, ValidationChain } from 'express-validator' | 2 | import { body, param, query, ValidationChain } from 'express-validator' |
3 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 3 | import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' |
4 | import { PluginType } from '../../../shared/models/plugins/plugin.type' | 4 | import { PluginType } from '../../../shared/models/plugins/plugin.type' |
5 | import { InstallOrUpdatePlugin } from '../../../shared/models/plugins/server/api/install-plugin.model' | 5 | import { InstallOrUpdatePlugin } from '../../../shared/models/plugins/server/api/install-plugin.model' |
6 | import { exists, isBooleanValid, isSafePath, toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc' | 6 | import { exists, isBooleanValid, isSafePath, toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc' |
diff --git a/server/middlewares/validators/redundancy.ts b/server/middlewares/validators/redundancy.ts index 116c8c611..f1b2ff5cd 100644 --- a/server/middlewares/validators/redundancy.ts +++ b/server/middlewares/validators/redundancy.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param, query } from 'express-validator' | 2 | import { body, param, query } from 'express-validator' |
3 | import { isVideoRedundancyTarget } from '@server/helpers/custom-validators/video-redundancies' | 3 | import { isVideoRedundancyTarget } from '@server/helpers/custom-validators/video-redundancies' |
4 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 4 | import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' |
5 | import { | 5 | import { |
6 | exists, | 6 | exists, |
7 | isBooleanValid, | 7 | isBooleanValid, |
diff --git a/server/middlewares/validators/search.ts b/server/middlewares/validators/search.ts index 7bbf81048..27d0e541d 100644 --- a/server/middlewares/validators/search.ts +++ b/server/middlewares/validators/search.ts | |||
@@ -1,13 +1,18 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { query } from 'express-validator' | 2 | import { query } from 'express-validator' |
3 | import { isSearchTargetValid } from '@server/helpers/custom-validators/search' | 3 | import { isSearchTargetValid } from '@server/helpers/custom-validators/search' |
4 | import { isDateValid } from '../../helpers/custom-validators/misc' | 4 | import { isHostValid } from '@server/helpers/custom-validators/servers' |
5 | import { areUUIDsValid, isDateValid, isNotEmptyStringArray, toCompleteUUIDs } from '../../helpers/custom-validators/misc' | ||
5 | import { logger } from '../../helpers/logger' | 6 | import { logger } from '../../helpers/logger' |
6 | import { areValidationErrors } from './shared' | 7 | import { areValidationErrors } from './shared' |
7 | 8 | ||
8 | const videosSearchValidator = [ | 9 | const videosSearchValidator = [ |
9 | query('search').optional().not().isEmpty().withMessage('Should have a valid search'), | 10 | query('search').optional().not().isEmpty().withMessage('Should have a valid search'), |
10 | 11 | ||
12 | query('host') | ||
13 | .optional() | ||
14 | .custom(isHostValid).withMessage('Should have a valid host'), | ||
15 | |||
11 | query('startDate') | 16 | query('startDate') |
12 | .optional() | 17 | .optional() |
13 | .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'), | 18 | .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'), |
@@ -22,8 +27,18 @@ const videosSearchValidator = [ | |||
22 | .optional() | 27 | .optional() |
23 | .custom(isDateValid).withMessage('Should have a published end date that conforms to ISO 8601'), | 28 | .custom(isDateValid).withMessage('Should have a published end date that conforms to ISO 8601'), |
24 | 29 | ||
25 | query('durationMin').optional().isInt().withMessage('Should have a valid min duration'), | 30 | query('durationMin') |
26 | query('durationMax').optional().isInt().withMessage('Should have a valid max duration'), | 31 | .optional() |
32 | .isInt().withMessage('Should have a valid min duration'), | ||
33 | query('durationMax') | ||
34 | .optional() | ||
35 | .isInt().withMessage('Should have a valid max duration'), | ||
36 | |||
37 | query('uuids') | ||
38 | .optional() | ||
39 | .toArray() | ||
40 | .customSanitizer(toCompleteUUIDs) | ||
41 | .custom(areUUIDsValid).withMessage('Should have valid uuids'), | ||
27 | 42 | ||
28 | query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'), | 43 | query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'), |
29 | 44 | ||
@@ -37,8 +52,22 @@ const videosSearchValidator = [ | |||
37 | ] | 52 | ] |
38 | 53 | ||
39 | const videoChannelsListSearchValidator = [ | 54 | const videoChannelsListSearchValidator = [ |
40 | query('search').not().isEmpty().withMessage('Should have a valid search'), | 55 | query('search') |
41 | query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'), | 56 | .optional() |
57 | .not().isEmpty().withMessage('Should have a valid search'), | ||
58 | |||
59 | query('host') | ||
60 | .optional() | ||
61 | .custom(isHostValid).withMessage('Should have a valid host'), | ||
62 | |||
63 | query('searchTarget') | ||
64 | .optional() | ||
65 | .custom(isSearchTargetValid).withMessage('Should have a valid search target'), | ||
66 | |||
67 | query('handles') | ||
68 | .optional() | ||
69 | .toArray() | ||
70 | .custom(isNotEmptyStringArray).withMessage('Should have valid handles'), | ||
42 | 71 | ||
43 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 72 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
44 | logger.debug('Checking video channels search query', { parameters: req.query }) | 73 | logger.debug('Checking video channels search query', { parameters: req.query }) |
@@ -50,8 +79,23 @@ const videoChannelsListSearchValidator = [ | |||
50 | ] | 79 | ] |
51 | 80 | ||
52 | const videoPlaylistsListSearchValidator = [ | 81 | const videoPlaylistsListSearchValidator = [ |
53 | query('search').not().isEmpty().withMessage('Should have a valid search'), | 82 | query('search') |
54 | query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'), | 83 | .optional() |
84 | .not().isEmpty().withMessage('Should have a valid search'), | ||
85 | |||
86 | query('host') | ||
87 | .optional() | ||
88 | .custom(isHostValid).withMessage('Should have a valid host'), | ||
89 | |||
90 | query('searchTarget') | ||
91 | .optional() | ||
92 | .custom(isSearchTargetValid).withMessage('Should have a valid search target'), | ||
93 | |||
94 | query('uuids') | ||
95 | .optional() | ||
96 | .toArray() | ||
97 | .customSanitizer(toCompleteUUIDs) | ||
98 | .custom(areUUIDsValid).withMessage('Should have valid uuids'), | ||
55 | 99 | ||
56 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 100 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
57 | logger.debug('Checking video playlists search query', { parameters: req.query }) | 101 | logger.debug('Checking video playlists search query', { parameters: req.query }) |
diff --git a/server/middlewares/validators/server.ts b/server/middlewares/validators/server.ts index fc7239b25..29fdc13d2 100644 --- a/server/middlewares/validators/server.ts +++ b/server/middlewares/validators/server.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body } from 'express-validator' | 2 | import { body } from 'express-validator' |
3 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 3 | import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' |
4 | import { isHostValid, isValidContactBody } from '../../helpers/custom-validators/servers' | 4 | import { isHostValid, isValidContactBody } from '../../helpers/custom-validators/servers' |
5 | import { isUserDisplayNameValid } from '../../helpers/custom-validators/users' | 5 | import { isUserDisplayNameValid } from '../../helpers/custom-validators/users' |
6 | import { logger } from '../../helpers/logger' | 6 | import { logger } from '../../helpers/logger' |
diff --git a/server/middlewares/validators/shared/abuses.ts b/server/middlewares/validators/shared/abuses.ts index 4a20a55fa..2b8d86ba5 100644 --- a/server/middlewares/validators/shared/abuses.ts +++ b/server/middlewares/validators/shared/abuses.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { Response } from 'express' | 1 | import { Response } from 'express' |
2 | import { AbuseModel } from '@server/models/abuse/abuse' | 2 | import { AbuseModel } from '@server/models/abuse/abuse' |
3 | import { HttpStatusCode } from '@shared/core-utils' | 3 | import { HttpStatusCode } from '@shared/models' |
4 | 4 | ||
5 | async function doesAbuseExist (abuseId: number | string, res: Response) { | 5 | async function doesAbuseExist (abuseId: number | string, res: Response) { |
6 | const abuse = await AbuseModel.loadByIdWithReporter(parseInt(abuseId + '', 10)) | 6 | const abuse = await AbuseModel.loadByIdWithReporter(parseInt(abuseId + '', 10)) |
diff --git a/server/middlewares/validators/shared/accounts.ts b/server/middlewares/validators/shared/accounts.ts index 04da15441..fe4f83aa0 100644 --- a/server/middlewares/validators/shared/accounts.ts +++ b/server/middlewares/validators/shared/accounts.ts | |||
@@ -2,7 +2,7 @@ import { Response } from 'express' | |||
2 | import { AccountModel } from '@server/models/account/account' | 2 | import { AccountModel } from '@server/models/account/account' |
3 | import { UserModel } from '@server/models/user/user' | 3 | import { UserModel } from '@server/models/user/user' |
4 | import { MAccountDefault } from '@server/types/models' | 4 | import { MAccountDefault } from '@server/types/models' |
5 | import { HttpStatusCode } from '@shared/core-utils' | 5 | import { HttpStatusCode } from '@shared/models' |
6 | 6 | ||
7 | function doesAccountIdExist (id: number | string, res: Response, sendNotFound = true) { | 7 | function doesAccountIdExist (id: number | string, res: Response, sendNotFound = true) { |
8 | const promise = AccountModel.load(parseInt(id + '', 10)) | 8 | const promise = AccountModel.load(parseInt(id + '', 10)) |
diff --git a/server/middlewares/validators/shared/video-blacklists.ts b/server/middlewares/validators/shared/video-blacklists.ts index 01491c10f..f85b39b23 100644 --- a/server/middlewares/validators/shared/video-blacklists.ts +++ b/server/middlewares/validators/shared/video-blacklists.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { Response } from 'express' | 1 | import { Response } from 'express' |
2 | import { VideoBlacklistModel } from '@server/models/video/video-blacklist' | 2 | import { VideoBlacklistModel } from '@server/models/video/video-blacklist' |
3 | import { HttpStatusCode } from '@shared/core-utils' | 3 | import { HttpStatusCode } from '@shared/models' |
4 | 4 | ||
5 | async function doesVideoBlacklistExist (videoId: number, res: Response) { | 5 | async function doesVideoBlacklistExist (videoId: number, res: Response) { |
6 | const videoBlacklist = await VideoBlacklistModel.loadByVideoId(videoId) | 6 | const videoBlacklist = await VideoBlacklistModel.loadByVideoId(videoId) |
diff --git a/server/middlewares/validators/shared/video-captions.ts b/server/middlewares/validators/shared/video-captions.ts index 80f6c5a52..831b366ea 100644 --- a/server/middlewares/validators/shared/video-captions.ts +++ b/server/middlewares/validators/shared/video-captions.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { Response } from 'express' | 1 | import { Response } from 'express' |
2 | import { VideoCaptionModel } from '@server/models/video/video-caption' | 2 | import { VideoCaptionModel } from '@server/models/video/video-caption' |
3 | import { MVideoId } from '@server/types/models' | 3 | import { MVideoId } from '@server/types/models' |
4 | import { HttpStatusCode } from '@shared/core-utils' | 4 | import { HttpStatusCode } from '@shared/models' |
5 | 5 | ||
6 | async function doesVideoCaptionExist (video: MVideoId, language: string, res: Response) { | 6 | async function doesVideoCaptionExist (video: MVideoId, language: string, res: Response) { |
7 | const videoCaption = await VideoCaptionModel.loadByVideoIdAndLanguage(video.id, language) | 7 | const videoCaption = await VideoCaptionModel.loadByVideoIdAndLanguage(video.id, language) |
diff --git a/server/middlewares/validators/shared/video-channels.ts b/server/middlewares/validators/shared/video-channels.ts index fe2e663b7..3fc3d012a 100644 --- a/server/middlewares/validators/shared/video-channels.ts +++ b/server/middlewares/validators/shared/video-channels.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { VideoChannelModel } from '@server/models/video/video-channel' | 2 | import { VideoChannelModel } from '@server/models/video/video-channel' |
3 | import { MChannelBannerAccountDefault } from '@server/types/models' | 3 | import { MChannelBannerAccountDefault } from '@server/types/models' |
4 | import { HttpStatusCode } from '@shared/core-utils' | 4 | import { HttpStatusCode } from '@shared/models' |
5 | 5 | ||
6 | async function doesLocalVideoChannelNameExist (name: string, res: express.Response) { | 6 | async function doesLocalVideoChannelNameExist (name: string, res: express.Response) { |
7 | const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name) | 7 | const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name) |
diff --git a/server/middlewares/validators/shared/video-comments.ts b/server/middlewares/validators/shared/video-comments.ts index 83ea15c98..60132fb6e 100644 --- a/server/middlewares/validators/shared/video-comments.ts +++ b/server/middlewares/validators/shared/video-comments.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { VideoCommentModel } from '@server/models/video/video-comment' | 2 | import { VideoCommentModel } from '@server/models/video/video-comment' |
3 | import { MVideoId } from '@server/types/models' | 3 | import { MVideoId } from '@server/types/models' |
4 | import { HttpStatusCode } from '@shared/core-utils' | 4 | import { HttpStatusCode } from '@shared/models' |
5 | 5 | ||
6 | async function doesVideoCommentThreadExist (idArg: number | string, video: MVideoId, res: express.Response) { | 6 | async function doesVideoCommentThreadExist (idArg: number | string, video: MVideoId, res: express.Response) { |
7 | const id = parseInt(idArg + '', 10) | 7 | const id = parseInt(idArg + '', 10) |
diff --git a/server/middlewares/validators/shared/video-imports.ts b/server/middlewares/validators/shared/video-imports.ts index 0f984bc17..50b49ffcb 100644 --- a/server/middlewares/validators/shared/video-imports.ts +++ b/server/middlewares/validators/shared/video-imports.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { VideoImportModel } from '@server/models/video/video-import' | 2 | import { VideoImportModel } from '@server/models/video/video-import' |
3 | import { HttpStatusCode } from '@shared/core-utils' | 3 | import { HttpStatusCode } from '@shared/models' |
4 | 4 | ||
5 | async function doesVideoImportExist (id: number, res: express.Response) { | 5 | async function doesVideoImportExist (id: number, res: express.Response) { |
6 | const videoImport = await VideoImportModel.loadAndPopulateVideo(id) | 6 | const videoImport = await VideoImportModel.loadAndPopulateVideo(id) |
diff --git a/server/middlewares/validators/shared/video-ownerships.ts b/server/middlewares/validators/shared/video-ownerships.ts index fc27006ce..93a23ef40 100644 --- a/server/middlewares/validators/shared/video-ownerships.ts +++ b/server/middlewares/validators/shared/video-ownerships.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { VideoChangeOwnershipModel } from '@server/models/video/video-change-ownership' | 2 | import { VideoChangeOwnershipModel } from '@server/models/video/video-change-ownership' |
3 | import { HttpStatusCode } from '@shared/core-utils' | 3 | import { HttpStatusCode } from '@shared/models' |
4 | 4 | ||
5 | async function doesChangeVideoOwnershipExist (idArg: number | string, res: express.Response) { | 5 | async function doesChangeVideoOwnershipExist (idArg: number | string, res: express.Response) { |
6 | const id = parseInt(idArg + '', 10) | 6 | const id = parseInt(idArg + '', 10) |
diff --git a/server/middlewares/validators/shared/video-playlists.ts b/server/middlewares/validators/shared/video-playlists.ts index d762859a8..3f6768179 100644 --- a/server/middlewares/validators/shared/video-playlists.ts +++ b/server/middlewares/validators/shared/video-playlists.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { VideoPlaylistModel } from '@server/models/video/video-playlist' | 2 | import { VideoPlaylistModel } from '@server/models/video/video-playlist' |
3 | import { MVideoPlaylist } from '@server/types/models' | 3 | import { MVideoPlaylist } from '@server/types/models' |
4 | import { HttpStatusCode } from '@shared/core-utils' | 4 | import { HttpStatusCode } from '@shared/models' |
5 | 5 | ||
6 | export type VideoPlaylistFetchType = 'summary' | 'all' | 6 | export type VideoPlaylistFetchType = 'summary' | 'all' |
7 | async function doesVideoPlaylistExist (id: number | string, res: express.Response, fetchType: VideoPlaylistFetchType = 'summary') { | 7 | async function doesVideoPlaylistExist (id: number | string, res: express.Response, fetchType: VideoPlaylistFetchType = 'summary') { |
diff --git a/server/middlewares/validators/shared/videos.ts b/server/middlewares/validators/shared/videos.ts index 2c66c1a3a..71b81654f 100644 --- a/server/middlewares/validators/shared/videos.ts +++ b/server/middlewares/validators/shared/videos.ts | |||
@@ -12,8 +12,7 @@ import { | |||
12 | MVideoImmutable, | 12 | MVideoImmutable, |
13 | MVideoThumbnail | 13 | MVideoThumbnail |
14 | } from '@server/types/models' | 14 | } from '@server/types/models' |
15 | import { HttpStatusCode } from '@shared/core-utils' | 15 | import { HttpStatusCode, UserRight } from '@shared/models' |
16 | import { UserRight } from '@shared/models' | ||
17 | 16 | ||
18 | async function doesVideoExist (id: number | string, res: Response, fetchType: VideoLoadType = 'all') { | 17 | async function doesVideoExist (id: number | string, res: Response, fetchType: VideoLoadType = 'all') { |
19 | const userId = res.locals.oauth ? res.locals.oauth.token.User.id : undefined | 18 | const userId = res.locals.oauth ? res.locals.oauth.token.User.id : undefined |
diff --git a/server/middlewares/validators/themes.ts b/server/middlewares/validators/themes.ts index d4716257f..2953b9505 100644 --- a/server/middlewares/validators/themes.ts +++ b/server/middlewares/validators/themes.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { param } from 'express-validator' | 2 | import { param } from 'express-validator' |
3 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 3 | import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' |
4 | import { isSafePath } from '../../helpers/custom-validators/misc' | 4 | import { isSafePath } from '../../helpers/custom-validators/misc' |
5 | import { isPluginNameValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins' | 5 | import { isPluginNameValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins' |
6 | import { logger } from '../../helpers/logger' | 6 | import { logger } from '../../helpers/logger' |
diff --git a/server/middlewares/validators/user-subscriptions.ts b/server/middlewares/validators/user-subscriptions.ts index ab7962923..df5777771 100644 --- a/server/middlewares/validators/user-subscriptions.ts +++ b/server/middlewares/validators/user-subscriptions.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param, query } from 'express-validator' | 2 | import { body, param, query } from 'express-validator' |
3 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 3 | import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' |
4 | import { areValidActorHandles, isValidActorHandle } from '../../helpers/custom-validators/activitypub/actor' | 4 | import { areValidActorHandles, isValidActorHandle } from '../../helpers/custom-validators/activitypub/actor' |
5 | import { toArray } from '../../helpers/custom-validators/misc' | 5 | import { toArray } from '../../helpers/custom-validators/misc' |
6 | import { logger } from '../../helpers/logger' | 6 | import { logger } from '../../helpers/logger' |
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts index 698d7d814..bc8607523 100644 --- a/server/middlewares/validators/users.ts +++ b/server/middlewares/validators/users.ts | |||
@@ -3,10 +3,9 @@ import { body, param, query } from 'express-validator' | |||
3 | import { omit } from 'lodash' | 3 | import { omit } from 'lodash' |
4 | import { Hooks } from '@server/lib/plugins/hooks' | 4 | import { Hooks } from '@server/lib/plugins/hooks' |
5 | import { MUserDefault } from '@server/types/models' | 5 | import { MUserDefault } from '@server/types/models' |
6 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 6 | import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' |
7 | import { UserRole } from '../../../shared/models/users' | 7 | import { UserRole } from '../../../shared/models/users' |
8 | import { UserRegister } from '../../../shared/models/users/user-register.model' | 8 | import { UserRegister } from '../../../shared/models/users/user-register.model' |
9 | import { isActorPreferredUsernameValid } from '../../helpers/custom-validators/activitypub/actor' | ||
10 | import { toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc' | 9 | import { toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc' |
11 | import { isThemeNameValid } from '../../helpers/custom-validators/plugins' | 10 | import { isThemeNameValid } from '../../helpers/custom-validators/plugins' |
12 | import { | 11 | import { |
@@ -28,7 +27,7 @@ import { | |||
28 | isUserVideoQuotaValid, | 27 | isUserVideoQuotaValid, |
29 | isUserVideosHistoryEnabledValid | 28 | isUserVideosHistoryEnabledValid |
30 | } from '../../helpers/custom-validators/users' | 29 | } from '../../helpers/custom-validators/users' |
31 | import { isVideoChannelNameValid } from '../../helpers/custom-validators/video-channels' | 30 | import { isVideoChannelDisplayNameValid, isVideoChannelUsernameValid } from '../../helpers/custom-validators/video-channels' |
32 | import { logger } from '../../helpers/logger' | 31 | import { logger } from '../../helpers/logger' |
33 | import { isThemeRegistered } from '../../lib/plugins/theme-utils' | 32 | import { isThemeRegistered } from '../../lib/plugins/theme-utils' |
34 | import { Redis } from '../../lib/redis' | 33 | import { Redis } from '../../lib/redis' |
@@ -56,9 +55,12 @@ const usersAddValidator = [ | |||
56 | body('username').custom(isUserUsernameValid).withMessage('Should have a valid username (lowercase alphanumeric characters)'), | 55 | body('username').custom(isUserUsernameValid).withMessage('Should have a valid username (lowercase alphanumeric characters)'), |
57 | body('password').custom(isUserPasswordValidOrEmpty).withMessage('Should have a valid password'), | 56 | body('password').custom(isUserPasswordValidOrEmpty).withMessage('Should have a valid password'), |
58 | body('email').isEmail().withMessage('Should have a valid email'), | 57 | body('email').isEmail().withMessage('Should have a valid email'), |
59 | body('channelName').optional().custom(isActorPreferredUsernameValid).withMessage('Should have a valid channel name'), | 58 | |
59 | body('channelName').optional().custom(isVideoChannelUsernameValid).withMessage('Should have a valid channel name'), | ||
60 | |||
60 | body('videoQuota').custom(isUserVideoQuotaValid).withMessage('Should have a valid user quota'), | 61 | body('videoQuota').custom(isUserVideoQuotaValid).withMessage('Should have a valid user quota'), |
61 | body('videoQuotaDaily').custom(isUserVideoQuotaDailyValid).withMessage('Should have a valid daily user quota'), | 62 | body('videoQuotaDaily').custom(isUserVideoQuotaDailyValid).withMessage('Should have a valid daily user quota'), |
63 | |||
62 | body('role') | 64 | body('role') |
63 | .customSanitizer(toIntOrNull) | 65 | .customSanitizer(toIntOrNull) |
64 | .custom(isUserRoleValid).withMessage('Should have a valid role'), | 66 | .custom(isUserRoleValid).withMessage('Should have a valid role'), |
@@ -106,10 +108,10 @@ const usersRegisterValidator = [ | |||
106 | 108 | ||
107 | body('channel.name') | 109 | body('channel.name') |
108 | .optional() | 110 | .optional() |
109 | .custom(isActorPreferredUsernameValid).withMessage('Should have a valid channel name'), | 111 | .custom(isVideoChannelUsernameValid).withMessage('Should have a valid channel name'), |
110 | body('channel.displayName') | 112 | body('channel.displayName') |
111 | .optional() | 113 | .optional() |
112 | .custom(isVideoChannelNameValid).withMessage('Should have a valid display name'), | 114 | .custom(isVideoChannelDisplayNameValid).withMessage('Should have a valid display name'), |
113 | 115 | ||
114 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 116 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
115 | logger.debug('Checking usersRegister parameters', { parameters: omit(req.body, 'password') }) | 117 | logger.debug('Checking usersRegister parameters', { parameters: omit(req.body, 'password') }) |
diff --git a/server/middlewares/validators/videos/video-blacklist.ts b/server/middlewares/validators/videos/video-blacklist.ts index 21141d84d..3a4937b7b 100644 --- a/server/middlewares/validators/videos/video-blacklist.ts +++ b/server/middlewares/validators/videos/video-blacklist.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, query } from 'express-validator' | 2 | import { body, query } from 'express-validator' |
3 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | 3 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' |
4 | import { isBooleanValid, toBooleanOrNull, toIntOrNull } from '../../../helpers/custom-validators/misc' | 4 | import { isBooleanValid, toBooleanOrNull, toIntOrNull } from '../../../helpers/custom-validators/misc' |
5 | import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../../helpers/custom-validators/video-blacklist' | 5 | import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../../helpers/custom-validators/video-blacklist' |
6 | import { logger } from '../../../helpers/logger' | 6 | import { logger } from '../../../helpers/logger' |
diff --git a/server/middlewares/validators/videos/video-channels.ts b/server/middlewares/validators/videos/video-channels.ts index e7df185e4..3b5693d23 100644 --- a/server/middlewares/validators/videos/video-channels.ts +++ b/server/middlewares/validators/videos/video-channels.ts | |||
@@ -3,13 +3,13 @@ import { body, param, query } from 'express-validator' | |||
3 | import { VIDEO_CHANNELS } from '@server/initializers/constants' | 3 | import { VIDEO_CHANNELS } from '@server/initializers/constants' |
4 | import { MChannelAccountDefault, MUser } from '@server/types/models' | 4 | import { MChannelAccountDefault, MUser } from '@server/types/models' |
5 | import { UserRight } from '../../../../shared' | 5 | import { UserRight } from '../../../../shared' |
6 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | 6 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' |
7 | import { isActorPreferredUsernameValid } from '../../../helpers/custom-validators/activitypub/actor' | ||
8 | import { isBooleanValid, toBooleanOrNull } from '../../../helpers/custom-validators/misc' | 7 | import { isBooleanValid, toBooleanOrNull } from '../../../helpers/custom-validators/misc' |
9 | import { | 8 | import { |
10 | isVideoChannelDescriptionValid, | 9 | isVideoChannelDescriptionValid, |
11 | isVideoChannelNameValid, | 10 | isVideoChannelDisplayNameValid, |
12 | isVideoChannelSupportValid | 11 | isVideoChannelSupportValid, |
12 | isVideoChannelUsernameValid | ||
13 | } from '../../../helpers/custom-validators/video-channels' | 13 | } from '../../../helpers/custom-validators/video-channels' |
14 | import { logger } from '../../../helpers/logger' | 14 | import { logger } from '../../../helpers/logger' |
15 | import { ActorModel } from '../../../models/actor/actor' | 15 | import { ActorModel } from '../../../models/actor/actor' |
@@ -17,8 +17,8 @@ import { VideoChannelModel } from '../../../models/video/video-channel' | |||
17 | import { areValidationErrors, doesLocalVideoChannelNameExist, doesVideoChannelNameWithHostExist } from '../shared' | 17 | import { areValidationErrors, doesLocalVideoChannelNameExist, doesVideoChannelNameWithHostExist } from '../shared' |
18 | 18 | ||
19 | const videoChannelsAddValidator = [ | 19 | const videoChannelsAddValidator = [ |
20 | body('name').custom(isActorPreferredUsernameValid).withMessage('Should have a valid channel name'), | 20 | body('name').custom(isVideoChannelUsernameValid).withMessage('Should have a valid channel name'), |
21 | body('displayName').custom(isVideoChannelNameValid).withMessage('Should have a valid display name'), | 21 | body('displayName').custom(isVideoChannelDisplayNameValid).withMessage('Should have a valid display name'), |
22 | body('description').optional().custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'), | 22 | body('description').optional().custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'), |
23 | body('support').optional().custom(isVideoChannelSupportValid).withMessage('Should have a valid support text'), | 23 | body('support').optional().custom(isVideoChannelSupportValid).withMessage('Should have a valid support text'), |
24 | 24 | ||
@@ -50,7 +50,7 @@ const videoChannelsUpdateValidator = [ | |||
50 | param('nameWithHost').exists().withMessage('Should have an video channel name with host'), | 50 | param('nameWithHost').exists().withMessage('Should have an video channel name with host'), |
51 | body('displayName') | 51 | body('displayName') |
52 | .optional() | 52 | .optional() |
53 | .custom(isVideoChannelNameValid).withMessage('Should have a valid display name'), | 53 | .custom(isVideoChannelDisplayNameValid).withMessage('Should have a valid display name'), |
54 | body('description') | 54 | body('description') |
55 | .optional() | 55 | .optional() |
56 | .custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'), | 56 | .custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'), |
@@ -117,7 +117,7 @@ const videoChannelsNameWithHostValidator = [ | |||
117 | ] | 117 | ] |
118 | 118 | ||
119 | const localVideoChannelValidator = [ | 119 | const localVideoChannelValidator = [ |
120 | param('name').custom(isVideoChannelNameValid).withMessage('Should have a valid video channel name'), | 120 | param('name').custom(isVideoChannelDisplayNameValid).withMessage('Should have a valid video channel name'), |
121 | 121 | ||
122 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 122 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
123 | logger.debug('Checking localVideoChannelValidator parameters', { parameters: req.params }) | 123 | logger.debug('Checking localVideoChannelValidator parameters', { parameters: req.params }) |
diff --git a/server/middlewares/validators/videos/video-comments.ts b/server/middlewares/validators/videos/video-comments.ts index 885506ebe..61c2ed92f 100644 --- a/server/middlewares/validators/videos/video-comments.ts +++ b/server/middlewares/validators/videos/video-comments.ts | |||
@@ -2,7 +2,7 @@ import * as express from 'express' | |||
2 | import { body, param, query } from 'express-validator' | 2 | import { body, param, query } from 'express-validator' |
3 | import { MUserAccountUrl } from '@server/types/models' | 3 | import { MUserAccountUrl } from '@server/types/models' |
4 | import { UserRight } from '../../../../shared' | 4 | import { UserRight } from '../../../../shared' |
5 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | 5 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' |
6 | import { exists, isBooleanValid, isIdValid, toBooleanOrNull } from '../../../helpers/custom-validators/misc' | 6 | import { exists, isBooleanValid, isIdValid, toBooleanOrNull } from '../../../helpers/custom-validators/misc' |
7 | import { isValidVideoCommentText } from '../../../helpers/custom-validators/video-comments' | 7 | import { isValidVideoCommentText } from '../../../helpers/custom-validators/video-comments' |
8 | import { logger } from '../../../helpers/logger' | 8 | import { logger } from '../../../helpers/logger' |
diff --git a/server/middlewares/validators/videos/video-imports.ts b/server/middlewares/validators/videos/video-imports.ts index 85dc647ce..52b839e56 100644 --- a/server/middlewares/validators/videos/video-imports.ts +++ b/server/middlewares/validators/videos/video-imports.ts | |||
@@ -2,7 +2,7 @@ import * as express from 'express' | |||
2 | import { body } from 'express-validator' | 2 | import { body } from 'express-validator' |
3 | import { isPreImportVideoAccepted } from '@server/lib/moderation' | 3 | import { isPreImportVideoAccepted } from '@server/lib/moderation' |
4 | import { Hooks } from '@server/lib/plugins/hooks' | 4 | import { Hooks } from '@server/lib/plugins/hooks' |
5 | import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' | 5 | import { HttpStatusCode } from '@shared/models' |
6 | import { VideoImportCreate } from '@shared/models/videos/import/video-import-create.model' | 6 | import { VideoImportCreate } from '@shared/models/videos/import/video-import-create.model' |
7 | import { isIdValid, toIntOrNull } from '../../../helpers/custom-validators/misc' | 7 | import { isIdValid, toIntOrNull } from '../../../helpers/custom-validators/misc' |
8 | import { isVideoImportTargetUrlValid, isVideoImportTorrentFile } from '../../../helpers/custom-validators/video-imports' | 8 | import { isVideoImportTargetUrlValid, isVideoImportTorrentFile } from '../../../helpers/custom-validators/video-imports' |
diff --git a/server/middlewares/validators/videos/video-live.ts b/server/middlewares/validators/videos/video-live.ts index 7cfb935e3..97e8b4510 100644 --- a/server/middlewares/validators/videos/video-live.ts +++ b/server/middlewares/validators/videos/video-live.ts | |||
@@ -5,8 +5,7 @@ import { isLocalLiveVideoAccepted } from '@server/lib/moderation' | |||
5 | import { Hooks } from '@server/lib/plugins/hooks' | 5 | import { Hooks } from '@server/lib/plugins/hooks' |
6 | import { VideoModel } from '@server/models/video/video' | 6 | import { VideoModel } from '@server/models/video/video' |
7 | import { VideoLiveModel } from '@server/models/video/video-live' | 7 | import { VideoLiveModel } from '@server/models/video/video-live' |
8 | import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' | 8 | import { HttpStatusCode, ServerErrorCode, UserRight, VideoState } from '@shared/models' |
9 | import { ServerErrorCode, UserRight, VideoState } from '@shared/models' | ||
10 | import { isBooleanValid, isIdValid, toBooleanOrNull, toIntOrNull } from '../../../helpers/custom-validators/misc' | 9 | import { isBooleanValid, isIdValid, toBooleanOrNull, toIntOrNull } from '../../../helpers/custom-validators/misc' |
11 | import { isVideoNameValid } from '../../../helpers/custom-validators/videos' | 10 | import { isVideoNameValid } from '../../../helpers/custom-validators/videos' |
12 | import { cleanUpReqFiles } from '../../../helpers/express-utils' | 11 | import { cleanUpReqFiles } from '../../../helpers/express-utils' |
diff --git a/server/middlewares/validators/videos/video-ownership-changes.ts b/server/middlewares/validators/videos/video-ownership-changes.ts index 54ac46c99..a7f0b72c3 100644 --- a/server/middlewares/validators/videos/video-ownership-changes.ts +++ b/server/middlewares/validators/videos/video-ownership-changes.ts | |||
@@ -6,8 +6,14 @@ import { logger } from '@server/helpers/logger' | |||
6 | import { isAbleToUploadVideo } from '@server/lib/user' | 6 | import { isAbleToUploadVideo } from '@server/lib/user' |
7 | import { AccountModel } from '@server/models/account/account' | 7 | import { AccountModel } from '@server/models/account/account' |
8 | import { MVideoWithAllFiles } from '@server/types/models' | 8 | import { MVideoWithAllFiles } from '@server/types/models' |
9 | import { HttpStatusCode } from '@shared/core-utils' | 9 | import { |
10 | import { ServerErrorCode, UserRight, VideoChangeOwnershipAccept, VideoChangeOwnershipStatus, VideoState } from '@shared/models' | 10 | HttpStatusCode, |
11 | ServerErrorCode, | ||
12 | UserRight, | ||
13 | VideoChangeOwnershipAccept, | ||
14 | VideoChangeOwnershipStatus, | ||
15 | VideoState | ||
16 | } from '@shared/models' | ||
11 | import { | 17 | import { |
12 | areValidationErrors, | 18 | areValidationErrors, |
13 | checkUserCanManageVideo, | 19 | checkUserCanManageVideo, |
diff --git a/server/middlewares/validators/videos/video-playlists.ts b/server/middlewares/validators/videos/video-playlists.ts index 5ee7ee0ce..ab84b4814 100644 --- a/server/middlewares/validators/videos/video-playlists.ts +++ b/server/middlewares/validators/videos/video-playlists.ts | |||
@@ -3,7 +3,7 @@ import { body, param, query, ValidationChain } from 'express-validator' | |||
3 | import { ExpressPromiseHandler } from '@server/types/express' | 3 | import { ExpressPromiseHandler } from '@server/types/express' |
4 | import { MUserAccountId } from '@server/types/models' | 4 | import { MUserAccountId } from '@server/types/models' |
5 | import { UserRight, VideoPlaylistCreate, VideoPlaylistUpdate } from '../../../../shared' | 5 | import { UserRight, VideoPlaylistCreate, VideoPlaylistUpdate } from '../../../../shared' |
6 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | 6 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' |
7 | import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' | 7 | import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' |
8 | import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model' | 8 | import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model' |
9 | import { | 9 | import { |
diff --git a/server/middlewares/validators/videos/video-rates.ts b/server/middlewares/validators/videos/video-rates.ts index 5d5dfb222..5fe78b39e 100644 --- a/server/middlewares/validators/videos/video-rates.ts +++ b/server/middlewares/validators/videos/video-rates.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param, query } from 'express-validator' | 2 | import { body, param, query } from 'express-validator' |
3 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | 3 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' |
4 | import { VideoRateType } from '../../../../shared/models/videos' | 4 | import { VideoRateType } from '../../../../shared/models/videos' |
5 | import { isAccountNameValid } from '../../../helpers/custom-validators/accounts' | 5 | import { isAccountNameValid } from '../../../helpers/custom-validators/accounts' |
6 | import { isIdValid } from '../../../helpers/custom-validators/misc' | 6 | import { isIdValid } from '../../../helpers/custom-validators/misc' |
diff --git a/server/middlewares/validators/videos/video-shares.ts b/server/middlewares/validators/videos/video-shares.ts index 7e54b6fc0..3b8d61768 100644 --- a/server/middlewares/validators/videos/video-shares.ts +++ b/server/middlewares/validators/videos/video-shares.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { param } from 'express-validator' | 2 | import { param } from 'express-validator' |
3 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | 3 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' |
4 | import { isIdValid } from '../../../helpers/custom-validators/misc' | 4 | import { isIdValid } from '../../../helpers/custom-validators/misc' |
5 | import { logger } from '../../../helpers/logger' | 5 | import { logger } from '../../../helpers/logger' |
6 | import { VideoShareModel } from '../../../models/video/video-share' | 6 | import { VideoShareModel } from '../../../models/video/video-share' |
diff --git a/server/middlewares/validators/videos/video-watch.ts b/server/middlewares/validators/videos/video-watch.ts index 43306f7cd..431515eb1 100644 --- a/server/middlewares/validators/videos/video-watch.ts +++ b/server/middlewares/validators/videos/video-watch.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body } from 'express-validator' | 2 | import { body } from 'express-validator' |
3 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | 3 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' |
4 | import { toIntOrNull } from '../../../helpers/custom-validators/misc' | 4 | import { toIntOrNull } from '../../../helpers/custom-validators/misc' |
5 | import { logger } from '../../../helpers/logger' | 5 | import { logger } from '../../../helpers/logger' |
6 | import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared' | 6 | import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared' |
diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts index 49e10e2b5..13187f398 100644 --- a/server/middlewares/validators/videos/videos.ts +++ b/server/middlewares/validators/videos/videos.ts | |||
@@ -6,7 +6,7 @@ import { getServerActor } from '@server/models/application/application' | |||
6 | import { ExpressPromiseHandler } from '@server/types/express' | 6 | import { ExpressPromiseHandler } from '@server/types/express' |
7 | import { MUserAccountId, MVideoFullLight } from '@server/types/models' | 7 | import { MUserAccountId, MVideoFullLight } from '@server/types/models' |
8 | import { ServerErrorCode, UserRight, VideoPrivacy } from '../../../../shared' | 8 | import { ServerErrorCode, UserRight, VideoPrivacy } from '../../../../shared' |
9 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | 9 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' |
10 | import { | 10 | import { |
11 | exists, | 11 | exists, |
12 | isBooleanValid, | 12 | isBooleanValid, |
@@ -188,7 +188,7 @@ const videosAddResumableInitValidator = getCommonVideoEditAttributes().concat([ | |||
188 | // multer required unsetting the Content-Type, now we can set it for node-uploadx | 188 | // multer required unsetting the Content-Type, now we can set it for node-uploadx |
189 | req.headers['content-type'] = 'application/json; charset=utf-8' | 189 | req.headers['content-type'] = 'application/json; charset=utf-8' |
190 | // place previewfile in metadata so that uploadx saves it in .META | 190 | // place previewfile in metadata so that uploadx saves it in .META |
191 | if (req.files['previewfile']) req.body.previewfile = req.files['previewfile'] | 191 | if (req.files?.['previewfile']) req.body.previewfile = req.files['previewfile'] |
192 | 192 | ||
193 | return next() | 193 | return next() |
194 | } | 194 | } |
diff --git a/server/middlewares/validators/webfinger.ts b/server/middlewares/validators/webfinger.ts index bcdd136c6..131360820 100644 --- a/server/middlewares/validators/webfinger.ts +++ b/server/middlewares/validators/webfinger.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { query } from 'express-validator' | 2 | import { query } from 'express-validator' |
3 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 3 | import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' |
4 | import { isWebfingerLocalResourceValid } from '../../helpers/custom-validators/webfinger' | 4 | import { isWebfingerLocalResourceValid } from '../../helpers/custom-validators/webfinger' |
5 | import { getHostWithPort } from '../../helpers/express-utils' | 5 | import { getHostWithPort } from '../../helpers/express-utils' |
6 | import { logger } from '../../helpers/logger' | 6 | import { logger } from '../../helpers/logger' |