aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2017-12-12 17:53:50 +0100
committerChocobozzz <me@florianbigard.com>2017-12-13 16:50:33 +0100
commit3fd3ab2d34d512b160a5e6084d7609be7b4f4452 (patch)
treee5ca358287fca6ecacce83defcf23af1e8e9f419 /server/middlewares/validators
parentc893d4514e6ecbf282c7985fe5f82b8acd8a1137 (diff)
downloadPeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.tar.gz
PeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.tar.zst
PeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.zip
Move models to typescript-sequelize
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r--server/middlewares/validators/account.ts4
-rw-r--r--server/middlewares/validators/activitypub/activity.ts3
-rw-r--r--server/middlewares/validators/activitypub/signature.ts4
-rw-r--r--server/middlewares/validators/follows.ts11
-rw-r--r--server/middlewares/validators/oembed.ts5
-rw-r--r--server/middlewares/validators/sort.ts1
-rw-r--r--server/middlewares/validators/users.ts15
-rw-r--r--server/middlewares/validators/utils.ts1
-rw-r--r--server/middlewares/validators/video-blacklist.ts13
-rw-r--r--server/middlewares/validators/video-channels.ts19
-rw-r--r--server/middlewares/validators/videos.ts17
-rw-r--r--server/middlewares/validators/webfinger.ts6
12 files changed, 50 insertions, 49 deletions
diff --git a/server/middlewares/validators/account.ts b/server/middlewares/validators/account.ts
index 70f4e4d3b..6951dfc80 100644
--- a/server/middlewares/validators/account.ts
+++ b/server/middlewares/validators/account.ts
@@ -1,7 +1,7 @@
1import * as express from 'express' 1import * as express from 'express'
2import { param } from 'express-validator/check' 2import { param } from 'express-validator/check'
3import { logger, isLocalAccountNameExist } from '../../helpers' 3import { logger } from '../../helpers'
4import { isAccountNameValid } from '../../helpers/custom-validators/accounts' 4import { isAccountNameValid, isLocalAccountNameExist } from '../../helpers/custom-validators/accounts'
5import { areValidationErrors } from './utils' 5import { areValidationErrors } from './utils'
6 6
7const localAccountValidator = [ 7const localAccountValidator = [
diff --git a/server/middlewares/validators/activitypub/activity.ts b/server/middlewares/validators/activitypub/activity.ts
index c63be5979..e0225f30c 100644
--- a/server/middlewares/validators/activitypub/activity.ts
+++ b/server/middlewares/validators/activitypub/activity.ts
@@ -1,6 +1,7 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body } from 'express-validator/check' 2import { body } from 'express-validator/check'
3import { isRootActivityValid, logger } from '../../../helpers' 3import { logger } from '../../../helpers'
4import { isRootActivityValid } from '../../../helpers/custom-validators/activitypub'
4import { areValidationErrors } from '../utils' 5import { areValidationErrors } from '../utils'
5 6
6const activityPubValidator = [ 7const activityPubValidator = [
diff --git a/server/middlewares/validators/activitypub/signature.ts b/server/middlewares/validators/activitypub/signature.ts
index 360685512..d41bb6a8d 100644
--- a/server/middlewares/validators/activitypub/signature.ts
+++ b/server/middlewares/validators/activitypub/signature.ts
@@ -1,6 +1,8 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body } from 'express-validator/check' 2import { body } from 'express-validator/check'
3import { isDateValid, isSignatureCreatorValid, isSignatureTypeValid, isSignatureValueValid, logger } from '../../../helpers' 3import { logger } from '../../../helpers'
4import { isSignatureCreatorValid, isSignatureTypeValid, isSignatureValueValid } from '../../../helpers/custom-validators/activitypub'
5import { isDateValid } from '../../../helpers/custom-validators/misc'
4import { areValidationErrors } from '../utils' 6import { areValidationErrors } from '../utils'
5 7
6const signatureValidator = [ 8const signatureValidator = [
diff --git a/server/middlewares/validators/follows.ts b/server/middlewares/validators/follows.ts
index 605872ecf..10482e5d0 100644
--- a/server/middlewares/validators/follows.ts
+++ b/server/middlewares/validators/follows.ts
@@ -1,12 +1,11 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, param } from 'express-validator/check' 2import { body, param } from 'express-validator/check'
3import { isTestInstance } from '../../helpers/core-utils' 3import { getServerAccount, isTestInstance, logger } from '../../helpers'
4import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
4import { isEachUniqueHostValid } from '../../helpers/custom-validators/servers' 5import { isEachUniqueHostValid } from '../../helpers/custom-validators/servers'
5import { logger } from '../../helpers/logger' 6import { CONFIG } from '../../initializers'
6import { CONFIG, database as db } from '../../initializers' 7import { AccountFollowModel } from '../../models/account/account-follow'
7import { areValidationErrors } from './utils' 8import { areValidationErrors } from './utils'
8import { getServerAccount } from '../../helpers/utils'
9import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
10 9
11const followValidator = [ 10const followValidator = [
12 body('hosts').custom(isEachUniqueHostValid).withMessage('Should have an array of unique hosts'), 11 body('hosts').custom(isEachUniqueHostValid).withMessage('Should have an array of unique hosts'),
@@ -38,7 +37,7 @@ const removeFollowingValidator = [
38 if (areValidationErrors(req, res)) return 37 if (areValidationErrors(req, res)) return
39 38
40 const serverAccount = await getServerAccount() 39 const serverAccount = await getServerAccount()
41 const follow = await db.AccountFollow.loadByAccountAndTarget(serverAccount.id, req.params.accountId) 40 const follow = await AccountFollowModel.loadByAccountAndTarget(serverAccount.id, req.params.accountId)
42 41
43 if (!follow) { 42 if (!follow) {
44 return res.status(404) 43 return res.status(404)
diff --git a/server/middlewares/validators/oembed.ts b/server/middlewares/validators/oembed.ts
index 31f06dc65..fb7b726e5 100644
--- a/server/middlewares/validators/oembed.ts
+++ b/server/middlewares/validators/oembed.ts
@@ -1,10 +1,11 @@
1import * as express from 'express' 1import * as express from 'express'
2import { query } from 'express-validator/check' 2import { query } from 'express-validator/check'
3import { join } from 'path' 3import { join } from 'path'
4import { isIdOrUUIDValid, isTestInstance, logger } from '../../helpers' 4import { isTestInstance, logger } from '../../helpers'
5import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
6import { isVideoExist } from '../../helpers/custom-validators/videos'
5import { CONFIG } from '../../initializers' 7import { CONFIG } from '../../initializers'
6import { areValidationErrors } from './utils' 8import { areValidationErrors } from './utils'
7import { isVideoExist } from '../../helpers/custom-validators/videos'
8 9
9const urlShouldStartWith = CONFIG.WEBSERVER.SCHEME + '://' + join(CONFIG.WEBSERVER.HOST, 'videos', 'watch') + '/' 10const urlShouldStartWith = CONFIG.WEBSERVER.SCHEME + '://' + join(CONFIG.WEBSERVER.HOST, 'videos', 'watch') + '/'
10const videoWatchRegex = new RegExp('([^/]+)$') 11const videoWatchRegex = new RegExp('([^/]+)$')
diff --git a/server/middlewares/validators/sort.ts b/server/middlewares/validators/sort.ts
index d5822ac81..38184fefa 100644
--- a/server/middlewares/validators/sort.ts
+++ b/server/middlewares/validators/sort.ts
@@ -1,6 +1,5 @@
1import { query } from 'express-validator/check' 1import { query } from 'express-validator/check'
2import * as express from 'express' 2import * as express from 'express'
3
4import { logger } from '../../helpers' 3import { logger } from '../../helpers'
5import { SORTABLE_COLUMNS } from '../../initializers' 4import { SORTABLE_COLUMNS } from '../../initializers'
6import { areValidationErrors } from './utils' 5import { areValidationErrors } from './utils'
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts
index ac7435b7d..920176d07 100644
--- a/server/middlewares/validators/users.ts
+++ b/server/middlewares/validators/users.ts
@@ -1,18 +1,17 @@
1import * as express from 'express' 1import * as express from 'express'
2import 'express-validator' 2import 'express-validator'
3import { body, param } from 'express-validator/check' 3import { body, param } from 'express-validator/check'
4import { isSignupAllowed, logger } from '../../helpers'
5import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
4import { 6import {
5 isIdOrUUIDValid,
6 isSignupAllowed,
7 isUserDisplayNSFWValid, 7 isUserDisplayNSFWValid,
8 isUserPasswordValid, 8 isUserPasswordValid,
9 isUserRoleValid, 9 isUserRoleValid,
10 isUserUsernameValid, 10 isUserUsernameValid,
11 isUserVideoQuotaValid, 11 isUserVideoQuotaValid
12 logger 12} from '../../helpers/custom-validators/users'
13} from '../../helpers'
14import { isVideoExist } from '../../helpers/custom-validators/videos' 13import { isVideoExist } from '../../helpers/custom-validators/videos'
15import { database as db } from '../../initializers/database' 14import { UserModel } from '../../models/account/user'
16import { areValidationErrors } from './utils' 15import { areValidationErrors } from './utils'
17 16
18const usersAddValidator = [ 17const usersAddValidator = [
@@ -153,7 +152,7 @@ export {
153// --------------------------------------------------------------------------- 152// ---------------------------------------------------------------------------
154 153
155async function checkUserIdExist (id: number, res: express.Response) { 154async function checkUserIdExist (id: number, res: express.Response) {
156 const user = await db.User.loadById(id) 155 const user = await UserModel.loadById(id)
157 156
158 if (!user) { 157 if (!user) {
159 res.status(404) 158 res.status(404)
@@ -168,7 +167,7 @@ async function checkUserIdExist (id: number, res: express.Response) {
168} 167}
169 168
170async function checkUserNameOrEmailDoesNotAlreadyExist (username: string, email: string, res: express.Response) { 169async function checkUserNameOrEmailDoesNotAlreadyExist (username: string, email: string, res: express.Response) {
171 const user = await db.User.loadByUsernameOrEmail(username, email) 170 const user = await UserModel.loadByUsernameOrEmail(username, email)
172 171
173 if (user) { 172 if (user) {
174 res.status(409) 173 res.status(409)
diff --git a/server/middlewares/validators/utils.ts b/server/middlewares/validators/utils.ts
index ca80acf29..61f76b457 100644
--- a/server/middlewares/validators/utils.ts
+++ b/server/middlewares/validators/utils.ts
@@ -1,6 +1,5 @@
1import * as express from 'express' 1import * as express from 'express'
2import { validationResult } from 'express-validator/check' 2import { validationResult } from 'express-validator/check'
3
4import { logger } from '../../helpers' 3import { logger } from '../../helpers'
5 4
6function areValidationErrors (req: express.Request, res: express.Response) { 5function areValidationErrors (req: express.Request, res: express.Response) {
diff --git a/server/middlewares/validators/video-blacklist.ts b/server/middlewares/validators/video-blacklist.ts
index f1cc04950..98099fe3f 100644
--- a/server/middlewares/validators/video-blacklist.ts
+++ b/server/middlewares/validators/video-blacklist.ts
@@ -1,9 +1,10 @@
1import * as express from 'express' 1import * as express from 'express'
2import { param } from 'express-validator/check' 2import { param } from 'express-validator/check'
3import { isIdOrUUIDValid, logger } from '../../helpers' 3import { logger } from '../../helpers'
4import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
4import { isVideoExist } from '../../helpers/custom-validators/videos' 5import { isVideoExist } from '../../helpers/custom-validators/videos'
5import { database as db } from '../../initializers/database' 6import { VideoModel } from '../../models/video/video'
6import { VideoInstance } from '../../models/video/video-interface' 7import { VideoBlacklistModel } from '../../models/video/video-blacklist'
7import { areValidationErrors } from './utils' 8import { areValidationErrors } from './utils'
8 9
9const videosBlacklistRemoveValidator = [ 10const videosBlacklistRemoveValidator = [
@@ -42,7 +43,7 @@ export {
42} 43}
43// --------------------------------------------------------------------------- 44// ---------------------------------------------------------------------------
44 45
45function checkVideoIsBlacklistable (video: VideoInstance, res: express.Response) { 46function checkVideoIsBlacklistable (video: VideoModel, res: express.Response) {
46 if (video.isOwned() === true) { 47 if (video.isOwned() === true) {
47 res.status(403) 48 res.status(403)
48 .json({ error: 'Cannot blacklist a local video' }) 49 .json({ error: 'Cannot blacklist a local video' })
@@ -54,8 +55,8 @@ function checkVideoIsBlacklistable (video: VideoInstance, res: express.Response)
54 return true 55 return true
55} 56}
56 57
57async function checkVideoIsBlacklisted (video: VideoInstance, res: express.Response) { 58async function checkVideoIsBlacklisted (video: VideoModel, res: express.Response) {
58 const blacklistedVideo = await db.BlacklistedVideo.loadByVideoId(video.id) 59 const blacklistedVideo = await VideoBlacklistModel.loadByVideoId(video.id)
59 if (!blacklistedVideo) { 60 if (!blacklistedVideo) {
60 res.status(404) 61 res.status(404)
61 .send('Blacklisted video not found') 62 .send('Blacklisted video not found')
diff --git a/server/middlewares/validators/video-channels.ts b/server/middlewares/validators/video-channels.ts
index 3d31a7e52..660390080 100644
--- a/server/middlewares/validators/video-channels.ts
+++ b/server/middlewares/validators/video-channels.ts
@@ -1,19 +1,18 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, param } from 'express-validator/check' 2import { body, param } from 'express-validator/check'
3import { UserRight } from '../../../shared' 3import { UserRight } from '../../../shared'
4import { isIdValid } from '../../helpers/custom-validators/misc' 4import { logger } from '../../helpers'
5import { isAccountIdExist } from '../../helpers/custom-validators/accounts'
6import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc'
5import { 7import {
6 isVideoChannelDescriptionValid, 8 isVideoChannelDescriptionValid,
7 isVideoChannelExist, 9 isVideoChannelExist,
8 isVideoChannelNameValid 10 isVideoChannelNameValid
9} from '../../helpers/custom-validators/video-channels' 11} from '../../helpers/custom-validators/video-channels'
10import { isIdOrUUIDValid } from '../../helpers/index' 12import { UserModel } from '../../models/account/user'
11import { logger } from '../../helpers/logger' 13import { VideoChannelModel } from '../../models/video/video-channel'
12import { database as db } from '../../initializers' 14import { VideoChannelShareModel } from '../../models/video/video-channel-share'
13import { UserInstance } from '../../models'
14import { areValidationErrors } from './utils' 15import { areValidationErrors } from './utils'
15import { isAccountIdExist } from '../../helpers/custom-validators/accounts'
16import { VideoChannelInstance } from '../../models/video/video-channel-interface'
17 16
18const listVideoAccountChannelsValidator = [ 17const listVideoAccountChannelsValidator = [
19 param('accountId').custom(isIdOrUUIDValid).withMessage('Should have a valid account id'), 18 param('accountId').custom(isIdOrUUIDValid).withMessage('Should have a valid account id'),
@@ -109,7 +108,7 @@ const videoChannelsShareValidator = [
109 if (areValidationErrors(req, res)) return 108 if (areValidationErrors(req, res)) return
110 if (!await isVideoChannelExist(req.params.id, res)) return 109 if (!await isVideoChannelExist(req.params.id, res)) return
111 110
112 const share = await db.VideoChannelShare.load(res.locals.video.id, req.params.accountId, undefined) 111 const share = await VideoChannelShareModel.load(res.locals.video.id, req.params.accountId, undefined)
113 if (!share) { 112 if (!share) {
114 return res.status(404) 113 return res.status(404)
115 .end() 114 .end()
@@ -134,7 +133,7 @@ export {
134 133
135// --------------------------------------------------------------------------- 134// ---------------------------------------------------------------------------
136 135
137function checkUserCanDeleteVideoChannel (user: UserInstance, videoChannel: VideoChannelInstance, res: express.Response) { 136function checkUserCanDeleteVideoChannel (user: UserModel, videoChannel: VideoChannelModel, res: express.Response) {
138 // Retrieve the user who did the request 137 // Retrieve the user who did the request
139 if (videoChannel.isOwned() === false) { 138 if (videoChannel.isOwned() === false) {
140 res.status(403) 139 res.status(403)
@@ -159,7 +158,7 @@ function checkUserCanDeleteVideoChannel (user: UserInstance, videoChannel: Video
159} 158}
160 159
161async function checkVideoChannelIsNotTheLastOne (res: express.Response) { 160async function checkVideoChannelIsNotTheLastOne (res: express.Response) {
162 const count = await db.VideoChannel.countByAccount(res.locals.oauth.token.User.Account.id) 161 const count = await VideoChannelModel.countByAccount(res.locals.oauth.token.User.Account.id)
163 162
164 if (count <= 1) { 163 if (count <= 1) {
165 res.status(409) 164 res.status(409)
diff --git a/server/middlewares/validators/videos.ts b/server/middlewares/validators/videos.ts
index 10625e41d..b52d5f285 100644
--- a/server/middlewares/validators/videos.ts
+++ b/server/middlewares/validators/videos.ts
@@ -1,6 +1,8 @@
1import * as express from 'express' 1import * as express from 'express'
2import 'express-validator'
2import { body, param, query } from 'express-validator/check' 3import { body, param, query } from 'express-validator/check'
3import { UserRight, VideoPrivacy } from '../../../shared' 4import { UserRight, VideoPrivacy } from '../../../shared'
5import { getDurationFromVideoFile, logger } from '../../helpers'
4import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc' 6import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc'
5import { 7import {
6 isVideoAbuseReasonValid, 8 isVideoAbuseReasonValid,
@@ -16,12 +18,11 @@ import {
16 isVideoRatingTypeValid, 18 isVideoRatingTypeValid,
17 isVideoTagsValid 19 isVideoTagsValid
18} from '../../helpers/custom-validators/videos' 20} from '../../helpers/custom-validators/videos'
19import { getDurationFromVideoFile } from '../../helpers/ffmpeg-utils'
20import { logger } from '../../helpers/logger'
21import { CONSTRAINTS_FIELDS } from '../../initializers' 21import { CONSTRAINTS_FIELDS } from '../../initializers'
22import { database as db } from '../../initializers/database' 22import { UserModel } from '../../models/account/user'
23import { UserInstance } from '../../models/account/user-interface' 23import { VideoModel } from '../../models/video/video'
24import { VideoInstance } from '../../models/video/video-interface' 24import { VideoChannelModel } from '../../models/video/video-channel'
25import { VideoShareModel } from '../../models/video/video-share'
25import { authenticate } from '../oauth' 26import { authenticate } from '../oauth'
26import { areValidationErrors } from './utils' 27import { areValidationErrors } from './utils'
27 28
@@ -48,7 +49,7 @@ const videosAddValidator = [
48 const videoFile: Express.Multer.File = req.files['videofile'][0] 49 const videoFile: Express.Multer.File = req.files['videofile'][0]
49 const user = res.locals.oauth.token.User 50 const user = res.locals.oauth.token.User
50 51
51 const videoChannel = await db.VideoChannel.loadByIdAndAccount(req.body.channelId, user.Account.id) 52 const videoChannel = await VideoChannelModel.loadByIdAndAccount(req.body.channelId, user.Account.id)
52 if (!videoChannel) { 53 if (!videoChannel) {
53 res.status(400) 54 res.status(400)
54 .json({ error: 'Unknown video video channel for this account.' }) 55 .json({ error: 'Unknown video video channel for this account.' })
@@ -221,7 +222,7 @@ const videosShareValidator = [
221 if (areValidationErrors(req, res)) return 222 if (areValidationErrors(req, res)) return
222 if (!await isVideoExist(req.params.id, res)) return 223 if (!await isVideoExist(req.params.id, res)) return
223 224
224 const share = await db.VideoShare.load(req.params.accountId, res.locals.video.id, undefined) 225 const share = await VideoShareModel.load(req.params.accountId, res.locals.video.id, undefined)
225 if (!share) { 226 if (!share) {
226 return res.status(404) 227 return res.status(404)
227 .end() 228 .end()
@@ -249,7 +250,7 @@ export {
249 250
250// --------------------------------------------------------------------------- 251// ---------------------------------------------------------------------------
251 252
252function checkUserCanDeleteVideo (user: UserInstance, video: VideoInstance, res: express.Response) { 253function checkUserCanDeleteVideo (user: UserModel, video: VideoModel, res: express.Response) {
253 // Retrieve the user who did the request 254 // Retrieve the user who did the request
254 if (video.isOwned() === false) { 255 if (video.isOwned() === false) {
255 res.status(403) 256 res.status(403)
diff --git a/server/middlewares/validators/webfinger.ts b/server/middlewares/validators/webfinger.ts
index 34e62c66d..7903c7400 100644
--- a/server/middlewares/validators/webfinger.ts
+++ b/server/middlewares/validators/webfinger.ts
@@ -1,8 +1,8 @@
1import * as express from 'express' 1import * as express from 'express'
2import { query } from 'express-validator/check' 2import { query } from 'express-validator/check'
3import { logger } from '../../helpers'
3import { isWebfingerResourceValid } from '../../helpers/custom-validators/webfinger' 4import { isWebfingerResourceValid } from '../../helpers/custom-validators/webfinger'
4import { logger } from '../../helpers/logger' 5import { AccountModel } from '../../models/account/account'
5import { database as db } from '../../initializers'
6import { areValidationErrors } from './utils' 6import { areValidationErrors } from './utils'
7 7
8const webfingerValidator = [ 8const webfingerValidator = [
@@ -17,7 +17,7 @@ const webfingerValidator = [
17 const nameWithHost = req.query.resource.substr(5) 17 const nameWithHost = req.query.resource.substr(5)
18 const [ name ] = nameWithHost.split('@') 18 const [ name ] = nameWithHost.split('@')
19 19
20 const account = await db.Account.loadLocalByName(name) 20 const account = await AccountModel.loadLocalByName(name)
21 if (!account) { 21 if (!account) {
22 return res.status(404) 22 return res.status(404)
23 .send({ error: 'Account not found' }) 23 .send({ error: 'Account not found' })