aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/custom-validators')
-rw-r--r--server/helpers/custom-validators/accounts.ts13
-rw-r--r--server/helpers/custom-validators/activitypub/account.ts2
-rw-r--r--server/helpers/custom-validators/activitypub/activity.ts4
-rw-r--r--server/helpers/custom-validators/activitypub/misc.ts4
-rw-r--r--server/helpers/custom-validators/index.ts9
-rw-r--r--server/helpers/custom-validators/video-channels.ts10
-rw-r--r--server/helpers/custom-validators/videos.ts19
-rw-r--r--server/helpers/custom-validators/webfinger.ts8
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'
2import { Response } from 'express' 2import { Response } from 'express'
3import 'express-validator' 3import 'express-validator'
4import * as validator from 'validator' 4import * as validator from 'validator'
5import { database as db } from '../../initializers' 5import { AccountModel } from '../../models/account/account'
6import { AccountInstance } from '../../models'
7import { isUserUsernameValid } from './users' 6import { isUserUsernameValid } from './users'
8 7
9function isAccountNameValid (value: string) { 8function isAccountNameValid (value: string) {
@@ -11,24 +10,24 @@ function isAccountNameValid (value: string) {
11} 10}
12 11
13function isAccountIdExist (id: number | string, res: Response) { 12function 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
25function isLocalAccountNameExist (name: string, res: Response) { 24function 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
31async function isAccountExist (p: Bluebird<AccountInstance>, res: Response) { 30async 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 @@
1import * as validator from 'validator' 1import * as validator from 'validator'
2import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' 2import { CONSTRAINTS_FIELDS } from '../../../initializers'
3import { isAccountNameValid } from '../accounts' 3import { isAccountNameValid } from '../accounts'
4import { exists, isUUIDValid } from '../misc' 4import { exists, isUUIDValid } from '../misc'
5import { isActivityPubUrlValid, isBaseActivityValid } from './misc' 5import { 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 @@
1import * as validator from 'validator' 1import * as validator from 'validator'
2import { Activity, ActivityType } from '../../../../shared/models/activitypub/activity' 2import { Activity, ActivityType } from '../../../../shared/models/activitypub'
3import { isAccountAcceptActivityValid, isAccountDeleteActivityValid, isAccountFollowActivityValid } from './account' 3import { isAccountAcceptActivityValid, isAccountDeleteActivityValid, isAccountFollowActivityValid } from './account'
4import { isAnnounceActivityValid } from './announce' 4import { isAnnounceActivityValid } from './announce'
5import { isActivityPubUrlValid } from './misc' 5import { isActivityPubUrlValid } from './misc'
6import { isDislikeActivityValid, isLikeActivityValid } from './rate'
6import { isUndoActivityValid } from './undo' 7import { isUndoActivityValid } from './undo'
7import { isVideoChannelCreateActivityValid, isVideoChannelDeleteActivityValid, isVideoChannelUpdateActivityValid } from './video-channels' 8import { isVideoChannelCreateActivityValid, isVideoChannelDeleteActivityValid, isVideoChannelUpdateActivityValid } from './video-channels'
8import { 9import {
@@ -12,7 +13,6 @@ import {
12 isVideoTorrentUpdateActivityValid 13 isVideoTorrentUpdateActivityValid
13} from './videos' 14} from './videos'
14import { isViewActivityValid } from './view' 15import { isViewActivityValid } from './view'
15import { isDislikeActivityValid, isLikeActivityValid } from './rate'
16 16
17function isRootActivityValid (activity: any) { 17function 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 @@
1import * as validator from 'validator' 1import * as validator from 'validator'
2import { exists } from '../misc' 2import { CONSTRAINTS_FIELDS } from '../../../initializers'
3import { isTestInstance } from '../../core-utils' 3import { isTestInstance } from '../../core-utils'
4import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' 4import { exists } from '../misc'
5 5
6function isActivityPubUrlValid (url: string) { 6function 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 @@
1export * from './activitypub'
2export * from './misc'
3export * from './servers'
4export * from './servers'
5export * from './users'
6export * from './accounts'
7export * from './video-channels'
8export * from './videos'
9export * 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'
2import 'express-validator' 2import 'express-validator'
3import 'multer' 3import 'multer'
4import * as validator from 'validator' 4import * as validator from 'validator'
5import { CONSTRAINTS_FIELDS, database as db } from '../../initializers' 5import { CONSTRAINTS_FIELDS } from '../../initializers'
6import { VideoChannelInstance } from '../../models' 6import { VideoChannelModel } from '../../models/video/video-channel'
7import { exists } from './misc' 7import { exists } from './misc'
8 8
9const VIDEO_CHANNELS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_CHANNELS 9const VIDEO_CHANNELS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_CHANNELS
@@ -17,11 +17,11 @@ function isVideoChannelNameValid (value: string) {
17} 17}
18 18
19async function isVideoChannelExist (id: string, res: express.Response) { 19async 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'
4import 'multer' 4import 'multer'
5import * as validator from 'validator' 5import * as validator from 'validator'
6import { VideoRateType } from '../../../shared' 6import { VideoRateType } from '../../../shared'
7import { CONSTRAINTS_FIELDS, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_RATE_TYPES } from '../../initializers' 7import {
8import { VIDEO_PRIVACIES } from '../../initializers/constants' 8 CONSTRAINTS_FIELDS,
9import { database as db } from '../../initializers/database' 9 VIDEO_CATEGORIES,
10import { VideoInstance } from '../../models/video/video-interface' 10 VIDEO_LANGUAGES,
11 VIDEO_LICENCES,
12 VIDEO_PRIVACIES,
13 VIDEO_RATE_TYPES
14} from '../../initializers'
15import { VideoModel } from '../../models/video/video'
11import { exists, isArray } from './misc' 16import { exists, isArray } from './misc'
12 17
13const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS 18const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS
@@ -100,12 +105,12 @@ function isVideoFileSizeValid (value: string) {
100} 105}
101 106
102async function isVideoExist (id: string, res: Response) { 107async 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 @@
1import 'express-validator' 1import { CONFIG } from '../../initializers'
2import 'multer'
3import { CONFIG } from '../../initializers/constants'
4import { exists } from './misc' 2import { exists } from './misc'
5 3
6function isWebfingerResourceValid (value: string) { 4function 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// ---------------------------------------------------------------------------