From 1e74f19a2179df7fc2e0da73163ef2c3118cbecb Mon Sep 17 00:00:00 2001 From: clementbrizard Date: Sat, 12 Jan 2019 13:45:23 +0000 Subject: Enable video upload and edit --- server/controllers/api/videos/index.ts | 8 +++++++- server/helpers/custom-validators/videos.ts | 7 ++++++- server/middlewares/validators/videos/videos.ts | 5 +++++ 3 files changed, 18 insertions(+), 2 deletions(-) (limited to 'server') diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 33521a8c1..b26dcabe1 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -188,7 +188,8 @@ async function addVideo (req: express.Request, res: express.Response) { support: videoInfo.support, privacy: videoInfo.privacy, duration: videoPhysicalFile['duration'], // duration was added by a previous middleware - channelId: res.locals.videoChannel.id + channelId: res.locals.videoChannel.id, + originallyPublishedAt: videoInfo.originallyPublishedAt } const video = new VideoModel(videoData) video.url = getVideoActivityPubUrl(video) // We use the UUID, so set the URL after building the object @@ -325,6 +326,11 @@ async function updateVideo (req: express.Request, res: express.Response) { if (videoInfoToUpdate.support !== undefined) videoInstance.set('support', videoInfoToUpdate.support) if (videoInfoToUpdate.description !== undefined) videoInstance.set('description', videoInfoToUpdate.description) if (videoInfoToUpdate.commentsEnabled !== undefined) videoInstance.set('commentsEnabled', videoInfoToUpdate.commentsEnabled) + if (videoInfoToUpdate.originallyPublishedAt !== undefined && + videoInfoToUpdate.originallyPublishedAt !== null) { + videoInstance.set('originallyPublishedAt', videoInfoToUpdate.originallyPublishedAt) + } + if (videoInfoToUpdate.privacy !== undefined) { const newPrivacy = parseInt(videoInfoToUpdate.privacy.toString(), 10) videoInstance.set('privacy', newPrivacy) diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index e6f22e6c5..ce4492a30 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts @@ -13,7 +13,7 @@ import { VIDEO_STATES } from '../../initializers' import { VideoModel } from '../../models/video/video' -import { exists, isArray, isFileValid } from './misc' +import { exists, isArray, isDateValid, isFileValid } from './misc' import { VideoChannelModel } from '../../models/video/video-channel' import { UserModel } from '../../models/account/user' import * as magnetUtil from 'magnet-uri' @@ -115,6 +115,10 @@ function isScheduleVideoUpdatePrivacyValid (value: number) { ) } +function isVideoOriginallyPublishedAtValid (value: string | null) { + return value === null || isDateValid(value) +} + function isVideoFileInfoHashValid (value: string | null | undefined) { return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.INFO_HASH) } @@ -220,6 +224,7 @@ export { isVideoTagsValid, isVideoFPSResolutionValid, isScheduleVideoUpdatePrivacyValid, + isVideoOriginallyPublishedAtValid, isVideoFile, isVideoMagnetUriValid, isVideoStateValid, diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts index 051a19e16..194d12c6e 100644 --- a/server/middlewares/validators/videos/videos.ts +++ b/server/middlewares/validators/videos/videos.ts @@ -14,6 +14,7 @@ import { } from '../../../helpers/custom-validators/misc' import { checkUserCanManageVideo, + isVideoOriginallyPublishedAtValid, isScheduleVideoUpdatePrivacyValid, isVideoCategoryValid, isVideoChannelOfAccountExist, @@ -340,6 +341,10 @@ function getCommonVideoAttributes () { .optional() .toBoolean() .custom(isBooleanValid).withMessage('Should have comments enabled boolean'), + body('originallyPublishedAt') + .optional() + .customSanitizer(toValueOrNull) + .custom(isVideoOriginallyPublishedAtValid).withMessage('Should have a valid original publication date'), body('scheduleUpdate') .optional() -- cgit v1.2.3