From 2baea0c77cc765f7cbca9c9a2f4272268892a35c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 14 Jun 2018 18:06:56 +0200 Subject: Add ability for uploaders to schedule video update --- server/controllers/api/users.ts | 6 +++++- server/controllers/api/videos/index.ts | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) (limited to 'server/controllers/api') diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts index 0aeb77964..891056912 100644 --- a/server/controllers/api/users.ts +++ b/server/controllers/api/users.ts @@ -174,7 +174,11 @@ async function getUserVideos (req: express.Request, res: express.Response, next: false // Display my NSFW videos ) - const additionalAttributes = { waitTranscoding: true, state: true } + const additionalAttributes = { + waitTranscoding: true, + state: true, + scheduledUpdate: true + } return res.json(getFormattedObjects(resultList.data, resultList.total, { additionalAttributes })) } diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 78963d89b..79ca4699f 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -52,6 +52,7 @@ import { rateVideoRouter } from './rate' import { VideoFilter } from '../../../../shared/models/videos/video-query.type' import { VideoSortField } from '../../../../client/src/app/shared/video/sort-field.type' import { createReqFiles, isNSFWHidden } from '../../../helpers/express-utils' +import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update' const videosRouter = express.Router() @@ -231,6 +232,7 @@ async function addVideo (req: express.Request, res: express.Response) { video.VideoFiles = [ videoFile ] + // Create tags if (videoInfo.tags !== undefined) { const tagInstances = await TagModel.findOrCreateTags(videoInfo.tags, t) @@ -238,6 +240,15 @@ async function addVideo (req: express.Request, res: express.Response) { video.Tags = tagInstances } + // Schedule an update in the future? + if (videoInfo.scheduleUpdate) { + await ScheduleVideoUpdateModel.create({ + videoId: video.id, + updateAt: videoInfo.scheduleUpdate.updateAt, + privacy: videoInfo.scheduleUpdate.privacy || null + }, { transaction: t }) + } + await federateVideoIfNeeded(video, true, t) logger.info('Video with name %s and uuid %s created.', videoInfo.name, videoCreated.uuid) @@ -324,6 +335,15 @@ async function updateVideo (req: express.Request, res: express.Response) { if (wasPrivateVideo === false) await changeVideoChannelShare(videoInstanceUpdated, oldVideoChannel, t) } + // Schedule an update in the future? + if (videoInfoToUpdate.scheduleUpdate) { + await ScheduleVideoUpdateModel.upsert({ + videoId: videoInstanceUpdated.id, + updateAt: videoInfoToUpdate.scheduleUpdate.updateAt, + privacy: videoInfoToUpdate.scheduleUpdate.privacy || null + }, { transaction: t }) + } + const isNewVideo = wasPrivateVideo && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo) }) -- cgit v1.2.3