]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/videos/update.ts
No notification on moderator abuse
[github/Chocobozzz/PeerTube.git] / server / controllers / api / videos / update.ts
index de5d94d5524132d12790071caec97c550bb7541a..e397127f31a819bd4e896f2d4cb3e8a871406360 100644 (file)
@@ -1,5 +1,6 @@
 import express from 'express'
 import { Transaction } from 'sequelize/types'
+import { updateTorrentMetadata } from '@server/helpers/webtorrent'
 import { changeVideoChannelShare } from '@server/lib/activitypub/share'
 import { buildVideoThumbnailsFromReq, setVideoTags } from '@server/lib/video'
 import { openapiOperationDoc } from '@server/middlewares/doc'
@@ -68,7 +69,7 @@ async function updateVideo (req: express.Request, res: express.Response) {
   })
 
   try {
-    const videoInstanceUpdated = await sequelizeTypescript.transaction(async t => {
+    const { videoInstanceUpdated, isNewVideo } = await sequelizeTypescript.transaction(async t => {
       // Refresh video since thumbnails to prevent concurrent updates
       const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoFromReq.id, t)
 
@@ -137,8 +138,6 @@ async function updateVideo (req: express.Request, res: express.Response) {
         transaction: t
       })
 
-      await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t)
-
       auditLogger.update(
         getAuditIdFromRes(res),
         new VideoAuditView(videoInstanceUpdated.toFormattedDetailsJSON()),
@@ -146,14 +145,16 @@ async function updateVideo (req: express.Request, res: express.Response) {
       )
       logger.info('Video with name %s and uuid %s updated.', video.name, video.uuid, lTags(video.uuid))
 
-      return videoInstanceUpdated
+      return { videoInstanceUpdated, isNewVideo }
     })
 
-    if (wasConfidentialVideo) {
-      Notifier.Instance.notifyOnNewVideoIfNeeded(videoInstanceUpdated)
-    }
+    if (videoInfoToUpdate.name) await updateTorrentsMetadata(videoInstanceUpdated)
+
+    await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, undefined)
+
+    if (wasConfidentialVideo) Notifier.Instance.notifyOnNewVideoIfNeeded(videoInstanceUpdated)
 
-    Hooks.runAction('action:api.video.updated', { video: videoInstanceUpdated, body: req.body })
+    Hooks.runAction('action:api.video.updated', { video: videoInstanceUpdated, body: req.body, req, res })
   } catch (err) {
     // Force fields we want to update
     // If the transaction is retried, sequelize will think the object has not changed
@@ -199,3 +200,20 @@ function updateSchedule (videoInstance: MVideoFullLight, videoInfoToUpdate: Vide
     return ScheduleVideoUpdateModel.deleteByVideoId(videoInstance.id, transaction)
   }
 }
+
+async function updateTorrentsMetadata (video: MVideoFullLight) {
+  for (const file of (video.VideoFiles || [])) {
+    await updateTorrentMetadata(video, file)
+
+    await file.save()
+  }
+
+  const hls = video.getHLSPlaylist()
+  if (!hls) return
+
+  for (const file of (hls.VideoFiles || [])) {
+    await updateTorrentMetadata(hls, file)
+
+    await file.save()
+  }
+}