From a2431b7dcbc72c05101dcdbe631ff84a823aeb51 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 27 Nov 2017 17:30:46 +0100 Subject: Refractor validators --- server/models/account/account.ts | 19 +++++++------------ server/models/video/video-channel.ts | 4 ++-- server/models/video/video.ts | 23 ++++++++++++++--------- 3 files changed, 23 insertions(+), 23 deletions(-) (limited to 'server/models') diff --git a/server/models/account/account.ts b/server/models/account/account.ts index fff3ce087..c721656cb 100644 --- a/server/models/account/account.ts +++ b/server/models/account/account.ts @@ -2,17 +2,12 @@ import * as Sequelize from 'sequelize' import { activityPubContextify, isAccountFollowersCountValid, - isAccountFollowersValid, isAccountFollowingCountValid, - isAccountFollowingValid, - isAccountInboxValid, - isAccountOutboxValid, isAccountPrivateKeyValid, isAccountPublicKeyValid, - isAccountSharedInboxValid, - isAccountUrlValid, isUserUsernameValid } from '../../helpers' +import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' import { CONFIG, CONSTRAINTS_FIELDS } from '../../initializers/constants' import { sendDeleteAccount } from '../../lib/activitypub/send/send-delete' @@ -61,7 +56,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes allowNull: false, validate: { urlValid: value => { - const res = isAccountUrlValid(value) + const res = isActivityPubUrlValid(value) if (res === false) throw new Error('URL is not valid.') } } @@ -111,7 +106,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes allowNull: false, validate: { inboxUrlValid: value => { - const res = isAccountInboxValid(value) + const res = isActivityPubUrlValid(value) if (res === false) throw new Error('Inbox URL is not valid.') } } @@ -121,7 +116,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes allowNull: false, validate: { outboxUrlValid: value => { - const res = isAccountOutboxValid(value) + const res = isActivityPubUrlValid(value) if (res === false) throw new Error('Outbox URL is not valid.') } } @@ -131,7 +126,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes allowNull: false, validate: { sharedInboxUrlValid: value => { - const res = isAccountSharedInboxValid(value) + const res = isActivityPubUrlValid(value) if (res === false) throw new Error('Shared inbox URL is not valid.') } } @@ -141,7 +136,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes allowNull: false, validate: { followersUrlValid: value => { - const res = isAccountFollowersValid(value) + const res = isActivityPubUrlValid(value) if (res === false) throw new Error('Followers URL is not valid.') } } @@ -151,7 +146,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes allowNull: false, validate: { followingUrlValid: value => { - const res = isAccountFollowingValid(value) + const res = isActivityPubUrlValid(value) if (res === false) throw new Error('Following URL is not valid.') } } diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index e11268b2c..54f12dce3 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts @@ -1,6 +1,5 @@ import * as Sequelize from 'sequelize' import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../../helpers' -import { isVideoChannelUrlValid } from '../../helpers/custom-validators/video-channels' import { CONSTRAINTS_FIELDS } from '../../initializers/constants' import { sendDeleteVideoChannel } from '../../lib/activitypub/send/send-delete' @@ -8,6 +7,7 @@ import { addMethodsToModel, getSort } from '../utils' import { VideoChannelAttributes, VideoChannelInstance, VideoChannelMethods } from './video-channel-interface' import { getAnnounceActivityPubUrl } from '../../lib/activitypub/url' import { activityPubCollection } from '../../helpers/activitypub' +import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' let VideoChannel: Sequelize.Model let toFormattedJSON: VideoChannelMethods.ToFormattedJSON @@ -66,7 +66,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da allowNull: false, validate: { urlValid: value => { - const res = isVideoChannelUrlValid(value) + const res = isActivityPubUrlValid(value) if (res === false) throw new Error('Video channel URL is not valid.') } } diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 4956b57ee..3f416d04c 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -7,7 +7,18 @@ import * as Sequelize from 'sequelize' import { VideoPrivacy, VideoResolution } from '../../../shared' import { VideoTorrentObject } from '../../../shared/models/activitypub/objects/video-torrent-object' import { activityPubCollection } from '../../helpers/activitypub' -import { isVideoCategoryValid, isVideoLanguageValid, isVideoPrivacyValid, isVideoUrlValid } from '../../helpers/custom-validators/videos' +import { createTorrentPromise, renamePromise, statPromise, unlinkPromise, writeFilePromise } from '../../helpers/core-utils' +import { isVideoCategoryValid, isVideoLanguageValid, isVideoPrivacyValid } from '../../helpers/custom-validators/videos' +import { generateImageFromVideoFile, getVideoFileHeight, transcode } from '../../helpers/ffmpeg-utils' +import { + isActivityPubUrlValid, + isVideoDescriptionValid, + isVideoDurationValid, + isVideoLicenceValid, + isVideoNameValid, + isVideoNSFWValid +} from '../../helpers/index' +import { logger } from '../../helpers/logger' import { API_VERSION, CONFIG, @@ -21,18 +32,12 @@ import { VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../initializers/constants' +import { getAnnounceActivityPubUrl } from '../../lib/activitypub/url' import { sendDeleteVideo } from '../../lib/index' - import { addMethodsToModel, getSort } from '../utils' - import { TagInstance } from './tag-interface' import { VideoFileInstance, VideoFileModel } from './video-file-interface' import { VideoAttributes, VideoInstance, VideoMethods } from './video-interface' -import { isVideoNameValid, isVideoLicenceValid, isVideoNSFWValid, isVideoDescriptionValid, isVideoDurationValid } from '../../helpers/index' -import { logger } from '../../helpers/logger' -import { generateImageFromVideoFile, transcode, getVideoFileHeight } from '../../helpers/ffmpeg-utils' -import { createTorrentPromise, writeFilePromise, unlinkPromise, renamePromise, statPromise } from '../../helpers/core-utils' -import { getAnnounceActivityPubUrl } from '../../lib/activitypub/url' let Video: Sequelize.Model let getOriginalFile: VideoMethods.GetOriginalFile @@ -205,7 +210,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da allowNull: false, validate: { urlValid: value => { - const res = isVideoUrlValid(value) + const res = isActivityPubUrlValid(value) if (res === false) throw new Error('Video URL is not valid.') } } -- cgit v1.2.3