]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/videos/index.ts
Fix images size limit
[github/Chocobozzz/PeerTube.git] / server / controllers / api / videos / index.ts
index 78963d89bd7358ea3dae840c542b2a800bb65d58..ca800a9a8bece715915a307b93d0b2845176479f 100644 (file)
@@ -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,8 +335,19 @@ 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 })
+      } else if (videoInfoToUpdate.scheduleUpdate === null) {
+        await ScheduleVideoUpdateModel.deleteByVideoId(videoInstanceUpdated.id, t)
+      }
+
       const isNewVideo = wasPrivateVideo && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE
-      await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo)
+      await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t)
     })
 
     logger.info('Video with name %s and uuid %s updated.', videoInstance.name, videoInstance.uuid)