]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/videos/ownership.ts
Add video file metadata to download modal, via ffprobe (#2411)
[github/Chocobozzz/PeerTube.git] / server / controllers / api / videos / ownership.ts
index bc247c4eeb418509d681857c4864e5082bef44a1..41d7cdc43b50b77b62e5f32a590f1848bd2caec6 100644 (file)
@@ -12,11 +12,13 @@ import {
   videosTerminateChangeOwnershipValidator
 } from '../../../middlewares'
 import { VideoChangeOwnershipModel } from '../../../models/video/video-change-ownership'
-import { VideoChangeOwnershipStatus, VideoPrivacy, VideoState } from '../../../../shared/models/videos'
+import { VideoChangeOwnershipStatus, VideoState } from '../../../../shared/models/videos'
 import { VideoChannelModel } from '../../../models/video/video-channel'
 import { getFormattedObjects } from '../../../helpers/utils'
 import { changeVideoChannelShare } from '../../../lib/activitypub'
 import { sendUpdateVideo } from '../../../lib/activitypub/send'
+import { VideoModel } from '../../../models/video/video'
+import { MVideoFullLight } from '@server/typings/models'
 
 const ownershipVideoRouter = express.Router()
 
@@ -55,7 +57,7 @@ export {
 // ---------------------------------------------------------------------------
 
 async function giveVideoOwnership (req: express.Request, res: express.Response) {
-  const videoInstance = res.locals.video
+  const videoInstance = res.locals.videoAll
   const initiatorAccountId = res.locals.oauth.token.User.Account.id
   const nextOwner = res.locals.nextOwner
 
@@ -97,21 +99,24 @@ async function listVideoOwnership (req: express.Request, res: express.Response)
 async function acceptOwnership (req: express.Request, res: express.Response) {
   return sequelizeTypescript.transaction(async t => {
     const videoChangeOwnership = res.locals.videoChangeOwnership
-    const targetVideo = videoChangeOwnership.Video
     const channel = res.locals.videoChannel
 
+    // We need more attributes for federation
+    const targetVideo = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoChangeOwnership.Video.id)
+
     const oldVideoChannel = await VideoChannelModel.loadByIdAndPopulateAccount(targetVideo.channelId)
 
-    targetVideo.set('channelId', channel.id)
-    const targetVideoUpdated = await targetVideo.save({ transaction: t })
+    targetVideo.channelId = channel.id
+
+    const targetVideoUpdated = await targetVideo.save({ transaction: t }) as MVideoFullLight
     targetVideoUpdated.VideoChannel = channel
 
-    if (targetVideoUpdated.privacy !== VideoPrivacy.PRIVATE && targetVideoUpdated.state === VideoState.PUBLISHED) {
+    if (targetVideoUpdated.hasPrivacyForFederation() && targetVideoUpdated.state === VideoState.PUBLISHED) {
       await changeVideoChannelShare(targetVideoUpdated, oldVideoChannel, t)
       await sendUpdateVideo(targetVideoUpdated, t, oldVideoChannel.Account.Actor)
     }
 
-    videoChangeOwnership.set('status', VideoChangeOwnershipStatus.ACCEPTED)
+    videoChangeOwnership.status = VideoChangeOwnershipStatus.ACCEPTED
     await videoChangeOwnership.save({ transaction: t })
 
     return res.sendStatus(204)
@@ -122,7 +127,7 @@ async function refuseOwnership (req: express.Request, res: express.Response) {
   return sequelizeTypescript.transaction(async t => {
     const videoChangeOwnership = res.locals.videoChangeOwnership
 
-    videoChangeOwnership.set('status', VideoChangeOwnershipStatus.REFUSED)
+    videoChangeOwnership.status = VideoChangeOwnershipStatus.REFUSED
     await videoChangeOwnership.save({ transaction: t })
 
     return res.sendStatus(204)