aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-02-03 09:33:05 +0100
committerChocobozzz <me@florianbigard.com>2021-02-03 09:45:08 +0100
commitba5a8d89bbf049e4afc41543bcc072cccdb02669 (patch)
tree6cc6b2dca17745cc0824c7ad4515f3bc4883fa4a /server/middlewares
parent29f148a61381727a432c22a71c7a2b7cc23d9c9e (diff)
downloadPeerTube-ba5a8d89bbf049e4afc41543bcc072cccdb02669.tar.gz
PeerTube-ba5a8d89bbf049e4afc41543bcc072cccdb02669.tar.zst
PeerTube-ba5a8d89bbf049e4afc41543bcc072cccdb02669.zip
Update server dependencies
Diffstat (limited to 'server/middlewares')
-rw-r--r--server/middlewares/async.ts5
-rw-r--r--server/middlewares/oauth.ts2
-rw-r--r--server/middlewares/validators/oembed.ts2
-rw-r--r--server/middlewares/validators/videos/video-playlists.ts23
-rw-r--r--server/middlewares/validators/videos/videos.ts5
5 files changed, 20 insertions, 17 deletions
diff --git a/server/middlewares/async.ts b/server/middlewares/async.ts
index 25b22596c..3a1bdabb8 100644
--- a/server/middlewares/async.ts
+++ b/server/middlewares/async.ts
@@ -1,12 +1,13 @@
1import { eachSeries } from 'async' 1import { eachSeries } from 'async'
2import { NextFunction, Request, RequestHandler, Response } from 'express' 2import { NextFunction, Request, RequestHandler, Response } from 'express'
3import { retryTransactionWrapper } from '../helpers/database-utils'
4import { ValidationChain } from 'express-validator' 3import { ValidationChain } from 'express-validator'
4import { ExpressPromiseHandler } from '@server/types/express'
5import { retryTransactionWrapper } from '../helpers/database-utils'
5 6
6// Syntactic sugar to avoid try/catch in express controllers 7// Syntactic sugar to avoid try/catch in express controllers
7// Thanks: https://medium.com/@Abazhenov/using-async-await-in-express-with-node-8-b8af872c0016 8// Thanks: https://medium.com/@Abazhenov/using-async-await-in-express-with-node-8-b8af872c0016
8 9
9export type RequestPromiseHandler = ValidationChain | ((req: Request, res: Response, next: NextFunction) => Promise<any>) 10export type RequestPromiseHandler = ValidationChain | ExpressPromiseHandler
10 11
11function asyncMiddleware (fun: RequestPromiseHandler | RequestPromiseHandler[]) { 12function asyncMiddleware (fun: RequestPromiseHandler | RequestPromiseHandler[]) {
12 return (req: Request, res: Response, next: NextFunction) => { 13 return (req: Request, res: Response, next: NextFunction) => {
diff --git a/server/middlewares/oauth.ts b/server/middlewares/oauth.ts
index ffc1b7ca9..47799153a 100644
--- a/server/middlewares/oauth.ts
+++ b/server/middlewares/oauth.ts
@@ -49,7 +49,7 @@ function authenticateSocket (socket: Socket, next: (err?: any) => void) {
49} 49}
50 50
51function authenticatePromiseIfNeeded (req: express.Request, res: express.Response, authenticateInQuery = false) { 51function authenticatePromiseIfNeeded (req: express.Request, res: express.Response, authenticateInQuery = false) {
52 return new Promise(resolve => { 52 return new Promise<void>(resolve => {
53 // Already authenticated? (or tried to) 53 // Already authenticated? (or tried to)
54 if (res.locals.oauth?.token.User) return resolve() 54 if (res.locals.oauth?.token.User) return resolve()
55 55
diff --git a/server/middlewares/validators/oembed.ts b/server/middlewares/validators/oembed.ts
index 86623efcd..2a7dc257b 100644
--- a/server/middlewares/validators/oembed.ts
+++ b/server/middlewares/validators/oembed.ts
@@ -14,7 +14,7 @@ import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-code
14const startVideoPlaylistsURL = WEBSERVER.SCHEME + '://' + join(WEBSERVER.HOST, 'videos', 'watch', 'playlist') + '/' 14const startVideoPlaylistsURL = WEBSERVER.SCHEME + '://' + join(WEBSERVER.HOST, 'videos', 'watch', 'playlist') + '/'
15const startVideosURL = WEBSERVER.SCHEME + '://' + join(WEBSERVER.HOST, 'videos', 'watch') + '/' 15const startVideosURL = WEBSERVER.SCHEME + '://' + join(WEBSERVER.HOST, 'videos', 'watch') + '/'
16 16
17const watchRegex = new RegExp('([^/]+)$') 17const watchRegex = /([^/]+)$/
18const isURLOptions = { 18const isURLOptions = {
19 require_host: true, 19 require_host: true,
20 require_tld: true 20 require_tld: true
diff --git a/server/middlewares/validators/videos/video-playlists.ts b/server/middlewares/validators/videos/video-playlists.ts
index c7a6f68e3..0fba4f5fd 100644
--- a/server/middlewares/validators/videos/video-playlists.ts
+++ b/server/middlewares/validators/videos/video-playlists.ts
@@ -1,10 +1,11 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, param, query, ValidationChain } from 'express-validator' 2import { body, param, query, ValidationChain } from 'express-validator'
3import { ExpressPromiseHandler } from '@server/types/express'
4import { MUserAccountId } from '@server/types/models'
3import { UserRight, VideoPlaylistCreate, VideoPlaylistUpdate } from '../../../../shared' 5import { UserRight, VideoPlaylistCreate, VideoPlaylistUpdate } from '../../../../shared'
4import { logger } from '../../../helpers/logger' 6import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
5import { areValidationErrors } from '../utils' 7import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
6import { isVideoImage } from '../../../helpers/custom-validators/videos' 8import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model'
7import { CONSTRAINTS_FIELDS } from '../../../initializers/constants'
8import { 9import {
9 isArrayOf, 10 isArrayOf,
10 isIdOrUUIDValid, 11 isIdOrUUIDValid,
@@ -21,15 +22,15 @@ import {
21 isVideoPlaylistTimestampValid, 22 isVideoPlaylistTimestampValid,
22 isVideoPlaylistTypeValid 23 isVideoPlaylistTypeValid
23} from '../../../helpers/custom-validators/video-playlists' 24} from '../../../helpers/custom-validators/video-playlists'
25import { isVideoImage } from '../../../helpers/custom-validators/videos'
24import { cleanUpReqFiles } from '../../../helpers/express-utils' 26import { cleanUpReqFiles } from '../../../helpers/express-utils'
25import { VideoPlaylistElementModel } from '../../../models/video/video-playlist-element' 27import { logger } from '../../../helpers/logger'
26import { authenticatePromiseIfNeeded } from '../../oauth'
27import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
28import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model'
29import { doesVideoChannelIdExist, doesVideoExist, doesVideoPlaylistExist, VideoPlaylistFetchType } from '../../../helpers/middlewares' 28import { doesVideoChannelIdExist, doesVideoExist, doesVideoPlaylistExist, VideoPlaylistFetchType } from '../../../helpers/middlewares'
29import { CONSTRAINTS_FIELDS } from '../../../initializers/constants'
30import { VideoPlaylistElementModel } from '../../../models/video/video-playlist-element'
30import { MVideoPlaylist } from '../../../types/models/video/video-playlist' 31import { MVideoPlaylist } from '../../../types/models/video/video-playlist'
31import { MUserAccountId } from '@server/types/models' 32import { authenticatePromiseIfNeeded } from '../../oauth'
32import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 33import { areValidationErrors } from '../utils'
33 34
34const videoPlaylistsAddValidator = getCommonPlaylistEditAttributes().concat([ 35const videoPlaylistsAddValidator = getCommonPlaylistEditAttributes().concat([
35 body('displayName') 36 body('displayName')
@@ -395,7 +396,7 @@ function getCommonPlaylistEditAttributes () {
395 body('videoChannelId') 396 body('videoChannelId')
396 .optional() 397 .optional()
397 .customSanitizer(toIntOrNull) 398 .customSanitizer(toIntOrNull)
398 ] as (ValidationChain | express.Handler)[] 399 ] as (ValidationChain | ExpressPromiseHandler)[]
399} 400}
400 401
401function checkUserCanManageVideoPlaylist (user: MUserAccountId, videoPlaylist: MVideoPlaylist, right: UserRight, res: express.Response) { 402function checkUserCanManageVideoPlaylist (user: MUserAccountId, videoPlaylist: MVideoPlaylist, right: UserRight, res: express.Response) {
diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts
index 84e309bec..26a671a1e 100644
--- a/server/middlewares/validators/videos/videos.ts
+++ b/server/middlewares/validators/videos/videos.ts
@@ -2,8 +2,10 @@ import * as express from 'express'
2import { body, param, query, ValidationChain } from 'express-validator' 2import { body, param, query, ValidationChain } from 'express-validator'
3import { isAbleToUploadVideo } from '@server/lib/user' 3import { isAbleToUploadVideo } from '@server/lib/user'
4import { getServerActor } from '@server/models/application/application' 4import { getServerActor } from '@server/models/application/application'
5import { ExpressPromiseHandler } from '@server/types/express'
5import { MVideoFullLight } from '@server/types/models' 6import { MVideoFullLight } from '@server/types/models'
6import { ServerErrorCode, UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../../shared' 7import { ServerErrorCode, UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../../shared'
8import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
7import { VideoChangeOwnershipAccept } from '../../../../shared/models/videos/video-change-ownership-accept.model' 9import { VideoChangeOwnershipAccept } from '../../../../shared/models/videos/video-change-ownership-accept.model'
8import { 10import {
9 exists, 11 exists,
@@ -54,7 +56,6 @@ import { AccountModel } from '../../../models/account/account'
54import { VideoModel } from '../../../models/video/video' 56import { VideoModel } from '../../../models/video/video'
55import { authenticatePromiseIfNeeded } from '../../oauth' 57import { authenticatePromiseIfNeeded } from '../../oauth'
56import { areValidationErrors } from '../utils' 58import { areValidationErrors } from '../utils'
57import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
58 59
59const videosAddValidator = getCommonVideoEditAttributes().concat([ 60const videosAddValidator = getCommonVideoEditAttributes().concat([
60 body('videofile') 61 body('videofile')
@@ -411,7 +412,7 @@ function getCommonVideoEditAttributes () {
411 .optional() 412 .optional()
412 .customSanitizer(toIntOrNull) 413 .customSanitizer(toIntOrNull)
413 .custom(isScheduleVideoUpdatePrivacyValid).withMessage('Should have correct schedule update privacy') 414 .custom(isScheduleVideoUpdatePrivacyValid).withMessage('Should have correct schedule update privacy')
414 ] as (ValidationChain | express.Handler)[] 415 ] as (ValidationChain | ExpressPromiseHandler)[]
415} 416}
416 417
417const commonVideosFiltersValidator = [ 418const commonVideosFiltersValidator = [