]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/process/process-add.ts
Fix lint
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / process / process-add.ts
index 433e68eb6c8a6dadffc01284515e5ebb069fa5ae..e6bf63eb245c68fa2b52fffe29fa314012e738e7 100644 (file)
@@ -11,7 +11,7 @@ import { VideoInstance } from '../../../models/video/video-interface'
 import { getOrCreateAccountAndServer } from '../account'
 import { getOrCreateVideoChannel } from '../video-channels'
 import { generateThumbnailFromUrl } from '../videos'
-import { videoActivityObjectToDBAttributes, videoFileActivityUrlToDBAttributes } from './misc'
+import { addVideoShares, videoActivityObjectToDBAttributes, videoFileActivityUrlToDBAttributes } from './misc'
 
 async function processAddActivity (activity: ActivityAdd) {
   const activityObject = activity.object
@@ -37,12 +37,10 @@ export {
 
 // ---------------------------------------------------------------------------
 
-async function processAddVideo (
-  account: AccountInstance,
-  activity: ActivityAdd,
-  videoChannel: VideoChannelInstance,
-  videoToCreateData: VideoTorrentObject
-) {
+async function processAddVideo (account: AccountInstance,
+                                activity: ActivityAdd,
+                                videoChannel: VideoChannelInstance,
+                                videoToCreateData: VideoTorrentObject) {
   const options = {
     arguments: [ account, activity, videoChannel, videoToCreateData ],
     errorMessage: 'Cannot insert the remote video with many retries.'
@@ -59,6 +57,10 @@ async function processAddVideo (
     await createRates(videoToCreateData.dislikes.orderedItems, video, 'dislike')
   }
 
+  if (videoToCreateData.shares && Array.isArray(videoToCreateData.shares.orderedItems)) {
+    await addVideoShares(video, videoToCreateData.shares.orderedItems)
+  }
+
   return video
 }
 
@@ -76,7 +78,7 @@ function addRemoteVideo (account: AccountInstance,
     if (videoChannel.Account.id !== account.id) throw new Error('Video channel is not owned by this account.')
 
     const videoFromDatabase = await db.Video.loadByUUIDOrURL(videoToCreateData.uuid, videoToCreateData.id, t)
-    if (videoFromDatabase) throw new Error('Video with this UUID/Url already exists.')
+    if (videoFromDatabase) return videoFromDatabase
 
     const videoData = await videoActivityObjectToDBAttributes(videoChannel, videoToCreateData, activity.to, activity.cc)
     const video = db.Video.build(videoData)