aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos/update.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/videos/update.ts')
-rw-r--r--server/controllers/api/videos/update.ts32
1 files changed, 25 insertions, 7 deletions
diff --git a/server/controllers/api/videos/update.ts b/server/controllers/api/videos/update.ts
index 3fcff3e86..589556f47 100644
--- a/server/controllers/api/videos/update.ts
+++ b/server/controllers/api/videos/update.ts
@@ -1,5 +1,6 @@
1import express from 'express' 1import express from 'express'
2import { Transaction } from 'sequelize/types' 2import { Transaction } from 'sequelize/types'
3import { updateTorrentMetadata } from '@server/helpers/webtorrent'
3import { changeVideoChannelShare } from '@server/lib/activitypub/share' 4import { changeVideoChannelShare } from '@server/lib/activitypub/share'
4import { buildVideoThumbnailsFromReq, setVideoTags } from '@server/lib/video' 5import { buildVideoThumbnailsFromReq, setVideoTags } from '@server/lib/video'
5import { openapiOperationDoc } from '@server/middlewares/doc' 6import { openapiOperationDoc } from '@server/middlewares/doc'
@@ -68,7 +69,7 @@ async function updateVideo (req: express.Request, res: express.Response) {
68 }) 69 })
69 70
70 try { 71 try {
71 const videoInstanceUpdated = await sequelizeTypescript.transaction(async t => { 72 const { videoInstanceUpdated, isNewVideo } = await sequelizeTypescript.transaction(async t => {
72 // Refresh video since thumbnails to prevent concurrent updates 73 // Refresh video since thumbnails to prevent concurrent updates
73 const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoFromReq.id, t) 74 const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoFromReq.id, t)
74 75
@@ -137,8 +138,6 @@ async function updateVideo (req: express.Request, res: express.Response) {
137 transaction: t 138 transaction: t
138 }) 139 })
139 140
140 await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t)
141
142 auditLogger.update( 141 auditLogger.update(
143 getAuditIdFromRes(res), 142 getAuditIdFromRes(res),
144 new VideoAuditView(videoInstanceUpdated.toFormattedDetailsJSON()), 143 new VideoAuditView(videoInstanceUpdated.toFormattedDetailsJSON()),
@@ -146,12 +145,14 @@ async function updateVideo (req: express.Request, res: express.Response) {
146 ) 145 )
147 logger.info('Video with name %s and uuid %s updated.', video.name, video.uuid, lTags(video.uuid)) 146 logger.info('Video with name %s and uuid %s updated.', video.name, video.uuid, lTags(video.uuid))
148 147
149 return videoInstanceUpdated 148 return { videoInstanceUpdated, isNewVideo }
150 }) 149 })
151 150
152 if (wasConfidentialVideo) { 151 if (videoInfoToUpdate.name) await updateTorrentsMetadata(videoInstanceUpdated)
153 Notifier.Instance.notifyOnNewVideoIfNeeded(videoInstanceUpdated) 152
154 } 153 await sequelizeTypescript.transaction(t => federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t))
154
155 if (wasConfidentialVideo) Notifier.Instance.notifyOnNewVideoIfNeeded(videoInstanceUpdated)
155 156
156 Hooks.runAction('action:api.video.updated', { video: videoInstanceUpdated, body: req.body, req, res }) 157 Hooks.runAction('action:api.video.updated', { video: videoInstanceUpdated, body: req.body, req, res })
157 } catch (err) { 158 } catch (err) {
@@ -199,3 +200,20 @@ function updateSchedule (videoInstance: MVideoFullLight, videoInfoToUpdate: Vide
199 return ScheduleVideoUpdateModel.deleteByVideoId(videoInstance.id, transaction) 200 return ScheduleVideoUpdateModel.deleteByVideoId(videoInstance.id, transaction)
200 } 201 }
201} 202}
203
204async function updateTorrentsMetadata (video: MVideoFullLight) {
205 for (const file of (video.VideoFiles || [])) {
206 await updateTorrentMetadata(video, file)
207
208 await file.save()
209 }
210
211 const hls = video.getHLSPlaylist()
212 if (!hls) return
213
214 for (const file of (hls.VideoFiles || [])) {
215 await updateTorrentMetadata(hls, file)
216
217 await file.save()
218 }
219}