From e6abf95e9fc9fde52d583850cf7faafdf7d050d5 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 26 Aug 2020 09:14:14 +0200 Subject: Add redirection on unavailable video due to follow constraints --- server/middlewares/validators/videos/videos.ts | 34 ++++++++++++++------------ 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'server/middlewares') diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts index 40a34d3b8..b022b2c23 100644 --- a/server/middlewares/validators/videos/videos.ts +++ b/server/middlewares/validators/videos/videos.ts @@ -1,6 +1,9 @@ import * as express from 'express' import { body, param, query, ValidationChain } from 'express-validator' -import { UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../../shared' +import { getServerActor } from '@server/models/application/application' +import { MVideoFullLight } from '@server/types/models' +import { ServerErrorCode, UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../../shared' +import { VideoChangeOwnershipAccept } from '../../../../shared/models/videos/video-change-ownership-accept.model' import { isBooleanValid, isDateValid, @@ -12,6 +15,8 @@ import { toIntOrNull, toValueOrNull } from '../../../helpers/custom-validators/misc' +import { isNSFWQueryValid, isNumberArray, isStringArray } from '../../../helpers/custom-validators/search' +import { checkUserCanTerminateOwnershipChange, doesChangeVideoOwnershipExist } from '../../../helpers/custom-validators/video-ownership' import { isScheduleVideoUpdatePrivacyValid, isVideoCategoryValid, @@ -27,29 +32,24 @@ import { isVideoSupportValid, isVideoTagsValid } from '../../../helpers/custom-validators/videos' +import { cleanUpReqFiles } from '../../../helpers/express-utils' import { getDurationFromVideoFile } from '../../../helpers/ffmpeg-utils' import { logger } from '../../../helpers/logger' -import { CONSTRAINTS_FIELDS, OVERVIEWS } from '../../../initializers/constants' -import { authenticatePromiseIfNeeded } from '../../oauth' -import { areValidationErrors } from '../utils' -import { cleanUpReqFiles } from '../../../helpers/express-utils' -import { VideoModel } from '../../../models/video/video' -import { checkUserCanTerminateOwnershipChange, doesChangeVideoOwnershipExist } from '../../../helpers/custom-validators/video-ownership' -import { VideoChangeOwnershipAccept } from '../../../../shared/models/videos/video-change-ownership-accept.model' -import { AccountModel } from '../../../models/account/account' -import { isNSFWQueryValid, isNumberArray, isStringArray } from '../../../helpers/custom-validators/search' -import { CONFIG } from '../../../initializers/config' -import { isLocalVideoAccepted } from '../../../lib/moderation' -import { Hooks } from '../../../lib/plugins/hooks' import { checkUserCanManageVideo, doesVideoChannelOfAccountExist, doesVideoExist, doesVideoFileOfVideoExist } from '../../../helpers/middlewares' -import { MVideoFullLight } from '@server/types/models' import { getVideoWithAttributes } from '../../../helpers/video' -import { getServerActor } from '@server/models/application/application' +import { CONFIG } from '../../../initializers/config' +import { CONSTRAINTS_FIELDS, OVERVIEWS } from '../../../initializers/constants' +import { isLocalVideoAccepted } from '../../../lib/moderation' +import { Hooks } from '../../../lib/plugins/hooks' +import { AccountModel } from '../../../models/account/account' +import { VideoModel } from '../../../models/video/video' +import { authenticatePromiseIfNeeded } from '../../oauth' +import { areValidationErrors } from '../utils' const videosAddValidator = getCommonVideoEditAttributes().concat([ body('videofile') @@ -148,7 +148,9 @@ async function checkVideoFollowConstraints (req: express.Request, res: express.R return res.status(403) .json({ - error: 'Cannot get this video regarding follow constraints.' + errorCode: ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS, + error: 'Cannot get this video regarding follow constraints.', + originUrl: video.url }) } -- cgit v1.2.3