From 38fa2065831b5f55be0d7f30f19a62c967397208 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 10 Nov 2017 14:48:08 +0100 Subject: Remove references to author --- server/helpers/custom-validators/index.ts | 1 + server/helpers/custom-validators/video-accounts.ts | 45 ++++++++++++++++++++++ server/helpers/custom-validators/video-channels.ts | 4 +- server/helpers/custom-validators/videos.ts | 4 +- 4 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 server/helpers/custom-validators/video-accounts.ts (limited to 'server/helpers/custom-validators') diff --git a/server/helpers/custom-validators/index.ts b/server/helpers/custom-validators/index.ts index 58a40249b..33922b8fe 100644 --- a/server/helpers/custom-validators/index.ts +++ b/server/helpers/custom-validators/index.ts @@ -3,5 +3,6 @@ export * from './misc' export * from './pods' export * from './pods' export * from './users' +export * from './video-accounts' export * from './video-channels' export * from './videos' diff --git a/server/helpers/custom-validators/video-accounts.ts b/server/helpers/custom-validators/video-accounts.ts new file mode 100644 index 000000000..3f3e9edd1 --- /dev/null +++ b/server/helpers/custom-validators/video-accounts.ts @@ -0,0 +1,45 @@ +import * as Promise from 'bluebird' +import * as validator from 'validator' +import * as express from 'express' +import 'express-validator' + +import { database as db } from '../../initializers' +import { AccountInstance } from '../../models' +import { logger } from '../logger' + +import { isUserUsernameValid } from './users' + +function isVideoAccountNameValid (value: string) { + return isUserUsernameValid(value) +} + +function checkVideoAccountExists (id: string, res: express.Response, callback: () => void) { + let promise: Promise + if (validator.isInt(id)) { + promise = db.Account.load(+id) + } else { // UUID + promise = db.Account.loadByUUID(id) + } + + promise.then(account => { + if (!account) { + return res.status(404) + .json({ error: 'Video account not found' }) + .end() + } + + res.locals.account = account + callback() + }) + .catch(err => { + logger.error('Error in video account request validator.', err) + return res.sendStatus(500) + }) +} + +// --------------------------------------------------------------------------- + +export { + checkVideoAccountExists, + isVideoAccountNameValid +} diff --git a/server/helpers/custom-validators/video-channels.ts b/server/helpers/custom-validators/video-channels.ts index b6be557e6..acc42f4a4 100644 --- a/server/helpers/custom-validators/video-channels.ts +++ b/server/helpers/custom-validators/video-channels.ts @@ -26,9 +26,9 @@ function isVideoChannelUUIDValid (value: string) { function checkVideoChannelExists (id: string, res: express.Response, callback: () => void) { let promise: Promise if (validator.isInt(id)) { - promise = db.VideoChannel.loadAndPopulateAuthor(+id) + promise = db.VideoChannel.loadAndPopulateAccount(+id) } else { // UUID - promise = db.VideoChannel.loadByUUIDAndPopulateAuthor(id) + promise = db.VideoChannel.loadByUUIDAndPopulateAccount(id) } promise.then(videoChannel => { diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index 83407f17b..487b3d646 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts @@ -166,9 +166,9 @@ function isVideoFileInfoHashValid (value: string) { function checkVideoExists (id: string, res: express.Response, callback: () => void) { let promise: Promise if (validator.isInt(id)) { - promise = db.Video.loadAndPopulateAuthorAndPodAndTags(+id) + promise = db.Video.loadAndPopulateAccountAndPodAndTags(+id) } else { // UUID - promise = db.Video.loadByUUIDAndPopulateAuthorAndPodAndTags(id) + promise = db.Video.loadByUUIDAndPopulateAccountAndPodAndTags(id) } promise.then(video => { -- cgit v1.2.3