diff options
author | Chocobozzz <me@florianbigard.com> | 2017-12-12 17:53:50 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2017-12-13 16:50:33 +0100 |
commit | 3fd3ab2d34d512b160a5e6084d7609be7b4f4452 (patch) | |
tree | e5ca358287fca6ecacce83defcf23af1e8e9f419 /server/helpers/custom-validators | |
parent | c893d4514e6ecbf282c7985fe5f82b8acd8a1137 (diff) | |
download | PeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.tar.gz PeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.tar.zst PeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.zip |
Move models to typescript-sequelize
Diffstat (limited to 'server/helpers/custom-validators')
-rw-r--r-- | server/helpers/custom-validators/accounts.ts | 13 | ||||
-rw-r--r-- | server/helpers/custom-validators/activitypub/account.ts | 2 | ||||
-rw-r--r-- | server/helpers/custom-validators/activitypub/activity.ts | 4 | ||||
-rw-r--r-- | server/helpers/custom-validators/activitypub/misc.ts | 4 | ||||
-rw-r--r-- | server/helpers/custom-validators/index.ts | 9 | ||||
-rw-r--r-- | server/helpers/custom-validators/video-channels.ts | 10 | ||||
-rw-r--r-- | server/helpers/custom-validators/videos.ts | 19 | ||||
-rw-r--r-- | server/helpers/custom-validators/webfinger.ts | 8 |
8 files changed, 30 insertions, 39 deletions
diff --git a/server/helpers/custom-validators/accounts.ts b/server/helpers/custom-validators/accounts.ts index e3c477414..8dc5d1f0d 100644 --- a/server/helpers/custom-validators/accounts.ts +++ b/server/helpers/custom-validators/accounts.ts | |||
@@ -2,8 +2,7 @@ import * as Bluebird from 'bluebird' | |||
2 | import { Response } from 'express' | 2 | import { Response } from 'express' |
3 | import 'express-validator' | 3 | import 'express-validator' |
4 | import * as validator from 'validator' | 4 | import * as validator from 'validator' |
5 | import { database as db } from '../../initializers' | 5 | import { AccountModel } from '../../models/account/account' |
6 | import { AccountInstance } from '../../models' | ||
7 | import { isUserUsernameValid } from './users' | 6 | import { isUserUsernameValid } from './users' |
8 | 7 | ||
9 | function isAccountNameValid (value: string) { | 8 | function isAccountNameValid (value: string) { |
@@ -11,24 +10,24 @@ function isAccountNameValid (value: string) { | |||
11 | } | 10 | } |
12 | 11 | ||
13 | function isAccountIdExist (id: number | string, res: Response) { | 12 | function isAccountIdExist (id: number | string, res: Response) { |
14 | let promise: Bluebird<AccountInstance> | 13 | let promise: Bluebird<AccountModel> |
15 | 14 | ||
16 | if (validator.isInt('' + id)) { | 15 | if (validator.isInt('' + id)) { |
17 | promise = db.Account.load(+id) | 16 | promise = AccountModel.load(+id) |
18 | } else { // UUID | 17 | } else { // UUID |
19 | promise = db.Account.loadByUUID('' + id) | 18 | promise = AccountModel.loadByUUID('' + id) |
20 | } | 19 | } |
21 | 20 | ||
22 | return isAccountExist(promise, res) | 21 | return isAccountExist(promise, res) |
23 | } | 22 | } |
24 | 23 | ||
25 | function isLocalAccountNameExist (name: string, res: Response) { | 24 | function isLocalAccountNameExist (name: string, res: Response) { |
26 | const promise = db.Account.loadLocalByName(name) | 25 | const promise = AccountModel.loadLocalByName(name) |
27 | 26 | ||
28 | return isAccountExist(promise, res) | 27 | return isAccountExist(promise, res) |
29 | } | 28 | } |
30 | 29 | ||
31 | async function isAccountExist (p: Bluebird<AccountInstance>, res: Response) { | 30 | async function isAccountExist (p: Bluebird<AccountModel>, res: Response) { |
32 | const account = await p | 31 | const account = await p |
33 | 32 | ||
34 | if (!account) { | 33 | if (!account) { |
diff --git a/server/helpers/custom-validators/activitypub/account.ts b/server/helpers/custom-validators/activitypub/account.ts index cab39a654..10bf81e8a 100644 --- a/server/helpers/custom-validators/activitypub/account.ts +++ b/server/helpers/custom-validators/activitypub/account.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import * as validator from 'validator' | 1 | import * as validator from 'validator' |
2 | import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' | 2 | import { CONSTRAINTS_FIELDS } from '../../../initializers' |
3 | import { isAccountNameValid } from '../accounts' | 3 | import { isAccountNameValid } from '../accounts' |
4 | import { exists, isUUIDValid } from '../misc' | 4 | import { exists, isUUIDValid } from '../misc' |
5 | import { isActivityPubUrlValid, isBaseActivityValid } from './misc' | 5 | import { isActivityPubUrlValid, isBaseActivityValid } from './misc' |
diff --git a/server/helpers/custom-validators/activitypub/activity.ts b/server/helpers/custom-validators/activitypub/activity.ts index 3a0e8197c..043e3c55e 100644 --- a/server/helpers/custom-validators/activitypub/activity.ts +++ b/server/helpers/custom-validators/activitypub/activity.ts | |||
@@ -1,8 +1,9 @@ | |||
1 | import * as validator from 'validator' | 1 | import * as validator from 'validator' |
2 | import { Activity, ActivityType } from '../../../../shared/models/activitypub/activity' | 2 | import { Activity, ActivityType } from '../../../../shared/models/activitypub' |
3 | import { isAccountAcceptActivityValid, isAccountDeleteActivityValid, isAccountFollowActivityValid } from './account' | 3 | import { isAccountAcceptActivityValid, isAccountDeleteActivityValid, isAccountFollowActivityValid } from './account' |
4 | import { isAnnounceActivityValid } from './announce' | 4 | import { isAnnounceActivityValid } from './announce' |
5 | import { isActivityPubUrlValid } from './misc' | 5 | import { isActivityPubUrlValid } from './misc' |
6 | import { isDislikeActivityValid, isLikeActivityValid } from './rate' | ||
6 | import { isUndoActivityValid } from './undo' | 7 | import { isUndoActivityValid } from './undo' |
7 | import { isVideoChannelCreateActivityValid, isVideoChannelDeleteActivityValid, isVideoChannelUpdateActivityValid } from './video-channels' | 8 | import { isVideoChannelCreateActivityValid, isVideoChannelDeleteActivityValid, isVideoChannelUpdateActivityValid } from './video-channels' |
8 | import { | 9 | import { |
@@ -12,7 +13,6 @@ import { | |||
12 | isVideoTorrentUpdateActivityValid | 13 | isVideoTorrentUpdateActivityValid |
13 | } from './videos' | 14 | } from './videos' |
14 | import { isViewActivityValid } from './view' | 15 | import { isViewActivityValid } from './view' |
15 | import { isDislikeActivityValid, isLikeActivityValid } from './rate' | ||
16 | 16 | ||
17 | function isRootActivityValid (activity: any) { | 17 | function isRootActivityValid (activity: any) { |
18 | return Array.isArray(activity['@context']) && | 18 | return Array.isArray(activity['@context']) && |
diff --git a/server/helpers/custom-validators/activitypub/misc.ts b/server/helpers/custom-validators/activitypub/misc.ts index 1bbfd0fc4..65f5ca809 100644 --- a/server/helpers/custom-validators/activitypub/misc.ts +++ b/server/helpers/custom-validators/activitypub/misc.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as validator from 'validator' | 1 | import * as validator from 'validator' |
2 | import { exists } from '../misc' | 2 | import { CONSTRAINTS_FIELDS } from '../../../initializers' |
3 | import { isTestInstance } from '../../core-utils' | 3 | import { isTestInstance } from '../../core-utils' |
4 | import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' | 4 | import { exists } from '../misc' |
5 | 5 | ||
6 | function isActivityPubUrlValid (url: string) { | 6 | function isActivityPubUrlValid (url: string) { |
7 | const isURLOptions = { | 7 | const isURLOptions = { |
diff --git a/server/helpers/custom-validators/index.ts b/server/helpers/custom-validators/index.ts deleted file mode 100644 index d3b2f5393..000000000 --- a/server/helpers/custom-validators/index.ts +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | export * from './activitypub' | ||
2 | export * from './misc' | ||
3 | export * from './servers' | ||
4 | export * from './servers' | ||
5 | export * from './users' | ||
6 | export * from './accounts' | ||
7 | export * from './video-channels' | ||
8 | export * from './videos' | ||
9 | export * from './webfinger' | ||
diff --git a/server/helpers/custom-validators/video-channels.ts b/server/helpers/custom-validators/video-channels.ts index 3de9f041b..6bc96bf51 100644 --- a/server/helpers/custom-validators/video-channels.ts +++ b/server/helpers/custom-validators/video-channels.ts | |||
@@ -2,8 +2,8 @@ import * as express from 'express' | |||
2 | import 'express-validator' | 2 | import 'express-validator' |
3 | import 'multer' | 3 | import 'multer' |
4 | import * as validator from 'validator' | 4 | import * as validator from 'validator' |
5 | import { CONSTRAINTS_FIELDS, database as db } from '../../initializers' | 5 | import { CONSTRAINTS_FIELDS } from '../../initializers' |
6 | import { VideoChannelInstance } from '../../models' | 6 | import { VideoChannelModel } from '../../models/video/video-channel' |
7 | import { exists } from './misc' | 7 | import { exists } from './misc' |
8 | 8 | ||
9 | const VIDEO_CHANNELS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_CHANNELS | 9 | const VIDEO_CHANNELS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_CHANNELS |
@@ -17,11 +17,11 @@ function isVideoChannelNameValid (value: string) { | |||
17 | } | 17 | } |
18 | 18 | ||
19 | async function isVideoChannelExist (id: string, res: express.Response) { | 19 | async function isVideoChannelExist (id: string, res: express.Response) { |
20 | let videoChannel: VideoChannelInstance | 20 | let videoChannel: VideoChannelModel |
21 | if (validator.isInt(id)) { | 21 | if (validator.isInt(id)) { |
22 | videoChannel = await db.VideoChannel.loadAndPopulateAccount(+id) | 22 | videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id) |
23 | } else { // UUID | 23 | } else { // UUID |
24 | videoChannel = await db.VideoChannel.loadByUUIDAndPopulateAccount(id) | 24 | videoChannel = await VideoChannelModel.loadByUUIDAndPopulateAccount(id) |
25 | } | 25 | } |
26 | 26 | ||
27 | if (!videoChannel) { | 27 | if (!videoChannel) { |
diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index 37fa8b08a..ee9d0ed19 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts | |||
@@ -4,10 +4,15 @@ import { values } from 'lodash' | |||
4 | import 'multer' | 4 | import 'multer' |
5 | import * as validator from 'validator' | 5 | import * as validator from 'validator' |
6 | import { VideoRateType } from '../../../shared' | 6 | import { VideoRateType } from '../../../shared' |
7 | import { CONSTRAINTS_FIELDS, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_RATE_TYPES } from '../../initializers' | 7 | import { |
8 | import { VIDEO_PRIVACIES } from '../../initializers/constants' | 8 | CONSTRAINTS_FIELDS, |
9 | import { database as db } from '../../initializers/database' | 9 | VIDEO_CATEGORIES, |
10 | import { VideoInstance } from '../../models/video/video-interface' | 10 | VIDEO_LANGUAGES, |
11 | VIDEO_LICENCES, | ||
12 | VIDEO_PRIVACIES, | ||
13 | VIDEO_RATE_TYPES | ||
14 | } from '../../initializers' | ||
15 | import { VideoModel } from '../../models/video/video' | ||
11 | import { exists, isArray } from './misc' | 16 | import { exists, isArray } from './misc' |
12 | 17 | ||
13 | const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS | 18 | const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS |
@@ -100,12 +105,12 @@ function isVideoFileSizeValid (value: string) { | |||
100 | } | 105 | } |
101 | 106 | ||
102 | async function isVideoExist (id: string, res: Response) { | 107 | async function isVideoExist (id: string, res: Response) { |
103 | let video: VideoInstance | 108 | let video: VideoModel |
104 | 109 | ||
105 | if (validator.isInt(id)) { | 110 | if (validator.isInt(id)) { |
106 | video = await db.Video.loadAndPopulateAccountAndServerAndTags(+id) | 111 | video = await VideoModel.loadAndPopulateAccountAndServerAndTags(+id) |
107 | } else { // UUID | 112 | } else { // UUID |
108 | video = await db.Video.loadByUUIDAndPopulateAccountAndServerAndTags(id) | 113 | video = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(id) |
109 | } | 114 | } |
110 | 115 | ||
111 | if (!video) { | 116 | if (!video) { |
diff --git a/server/helpers/custom-validators/webfinger.ts b/server/helpers/custom-validators/webfinger.ts index e93115d81..38f6b938d 100644 --- a/server/helpers/custom-validators/webfinger.ts +++ b/server/helpers/custom-validators/webfinger.ts | |||
@@ -1,6 +1,4 @@ | |||
1 | import 'express-validator' | 1 | import { CONFIG } from '../../initializers' |
2 | import 'multer' | ||
3 | import { CONFIG } from '../../initializers/constants' | ||
4 | import { exists } from './misc' | 2 | import { exists } from './misc' |
5 | 3 | ||
6 | function isWebfingerResourceValid (value: string) { | 4 | function isWebfingerResourceValid (value: string) { |
@@ -13,9 +11,7 @@ function isWebfingerResourceValid (value: string) { | |||
13 | 11 | ||
14 | const host = accountParts[1] | 12 | const host = accountParts[1] |
15 | 13 | ||
16 | if (host !== CONFIG.WEBSERVER.HOST) return false | 14 | return host === CONFIG.WEBSERVER.HOST |
17 | |||
18 | return true | ||
19 | } | 15 | } |
20 | 16 | ||
21 | // --------------------------------------------------------------------------- | 17 | // --------------------------------------------------------------------------- |