aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-16 15:55:01 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:52 +0100
commitd7d5611c8a23de9b483f0437ad3469afef7b8805 (patch)
tree35f8f77e5f211a65f8be3c967e939f83c7e17d29 /server/lib/activitypub
parent20494f122186bb1bfd82f4c598c4744acea27b0c (diff)
downloadPeerTube-d7d5611c8a23de9b483f0437ad3469afef7b8805.tar.gz
PeerTube-d7d5611c8a23de9b483f0437ad3469afef7b8805.tar.zst
PeerTube-d7d5611c8a23de9b483f0437ad3469afef7b8805.zip
Federate video update
Diffstat (limited to 'server/lib/activitypub')
-rw-r--r--server/lib/activitypub/misc.ts6
-rw-r--r--server/lib/activitypub/process-add.ts13
-rw-r--r--server/lib/activitypub/process-create.ts2
-rw-r--r--server/lib/activitypub/process-delete.ts2
-rw-r--r--server/lib/activitypub/process-update.ts4
-rw-r--r--server/lib/activitypub/send-request.ts20
6 files changed, 29 insertions, 18 deletions
diff --git a/server/lib/activitypub/misc.ts b/server/lib/activitypub/misc.ts
index 13838fc4c..f853d742e 100644
--- a/server/lib/activitypub/misc.ts
+++ b/server/lib/activitypub/misc.ts
@@ -25,12 +25,8 @@ function videoChannelActivityObjectToDBAttributes (videoChannelObject: VideoChan
25 25
26async function videoActivityObjectToDBAttributes ( 26async function videoActivityObjectToDBAttributes (
27 videoChannel: VideoChannelInstance, 27 videoChannel: VideoChannelInstance,
28 videoObject: VideoTorrentObject, 28 videoObject: VideoTorrentObject
29 t: Sequelize.Transaction
30) { 29) {
31 const videoFromDatabase = await db.Video.loadByUUIDOrURL(videoObject.uuid, videoObject.id, t)
32 if (videoFromDatabase) throw new Error('Video with this UUID/Url already exists.')
33
34 const duration = videoObject.duration.replace(/[^\d]+/, '') 30 const duration = videoObject.duration.replace(/[^\d]+/, '')
35 const videoData: VideoAttributes = { 31 const videoData: VideoAttributes = {
36 name: videoObject.name, 32 name: videoObject.name,
diff --git a/server/lib/activitypub/process-add.ts b/server/lib/activitypub/process-add.ts
index df7139d46..72c5b1932 100644
--- a/server/lib/activitypub/process-add.ts
+++ b/server/lib/activitypub/process-add.ts
@@ -1,12 +1,12 @@
1import * as Bluebird from 'bluebird'
1import { VideoTorrentObject } from '../../../shared' 2import { VideoTorrentObject } from '../../../shared'
2import { ActivityAdd } from '../../../shared/models/activitypub/activity' 3import { ActivityAdd } from '../../../shared/models/activitypub/activity'
3import { generateThumbnailFromUrl, logger, retryTransactionWrapper, getOrCreateAccount } from '../../helpers' 4import { generateThumbnailFromUrl, getOrCreateAccount, logger, retryTransactionWrapper } from '../../helpers'
5import { getOrCreateVideoChannel } from '../../helpers/activitypub'
4import { database as db } from '../../initializers' 6import { database as db } from '../../initializers'
5import { AccountInstance } from '../../models/account/account-interface' 7import { AccountInstance } from '../../models/account/account-interface'
6import { videoActivityObjectToDBAttributes, videoFileActivityUrlToDBAttributes } from './misc'
7import Bluebird = require('bluebird')
8import { getOrCreateVideoChannel } from '../../helpers/activitypub'
9import { VideoChannelInstance } from '../../models/video/video-channel-interface' 8import { VideoChannelInstance } from '../../models/video/video-channel-interface'
9import { videoActivityObjectToDBAttributes, videoFileActivityUrlToDBAttributes } from './misc'
10 10
11async function processAddActivity (activity: ActivityAdd) { 11async function processAddActivity (activity: ActivityAdd) {
12 const activityObject = activity.object 12 const activityObject = activity.object
@@ -51,7 +51,10 @@ function addRemoteVideo (account: AccountInstance, videoChannel: VideoChannelIns
51 51
52 if (videoChannel.Account.id !== account.id) throw new Error('Video channel is not owned by this account.') 52 if (videoChannel.Account.id !== account.id) throw new Error('Video channel is not owned by this account.')
53 53
54 const videoData = await videoActivityObjectToDBAttributes(videoChannel, videoToCreateData, t) 54 const videoFromDatabase = await db.Video.loadByUUIDOrURL(videoToCreateData.uuid, videoToCreateData.id, t)
55 if (videoFromDatabase) throw new Error('Video with this UUID/Url already exists.')
56
57 const videoData = await videoActivityObjectToDBAttributes(videoChannel, videoToCreateData)
55 const video = db.Video.build(videoData) 58 const video = db.Video.build(videoData)
56 59
57 // Don't block on request 60 // Don't block on request
diff --git a/server/lib/activitypub/process-create.ts b/server/lib/activitypub/process-create.ts
index c4706a66b..faea3f48a 100644
--- a/server/lib/activitypub/process-create.ts
+++ b/server/lib/activitypub/process-create.ts
@@ -69,7 +69,7 @@ function addRemoteVideoAbuse (account: AccountInstance, videoAbuseToCreateData:
69 logger.debug('Reporting remote abuse for video %s.', videoAbuseToCreateData.object) 69 logger.debug('Reporting remote abuse for video %s.', videoAbuseToCreateData.object)
70 70
71 return db.sequelize.transaction(async t => { 71 return db.sequelize.transaction(async t => {
72 const video = await db.Video.loadByUrl(videoAbuseToCreateData.object, t) 72 const video = await db.Video.loadByUrlAndPopulateAccount(videoAbuseToCreateData.object, t)
73 if (!video) { 73 if (!video) {
74 logger.warn('Unknown video %s for remote video abuse.', videoAbuseToCreateData.object) 74 logger.warn('Unknown video %s for remote video abuse.', videoAbuseToCreateData.object)
75 return 75 return
diff --git a/server/lib/activitypub/process-delete.ts b/server/lib/activitypub/process-delete.ts
index 377df432d..d4487d2cc 100644
--- a/server/lib/activitypub/process-delete.ts
+++ b/server/lib/activitypub/process-delete.ts
@@ -15,7 +15,7 @@ async function processDeleteActivity (activity: ActivityDelete) {
15 } 15 }
16 16
17 { 17 {
18 let videoObject = await db.Video.loadByUrl(activity.id) 18 let videoObject = await db.Video.loadByUrlAndPopulateAccount(activity.id)
19 if (videoObject !== undefined) { 19 if (videoObject !== undefined) {
20 return processDeleteVideo(account, videoObject) 20 return processDeleteVideo(account, videoObject)
21 } 21 }
diff --git a/server/lib/activitypub/process-update.ts b/server/lib/activitypub/process-update.ts
index cd8a4b8e2..4aefd1b9b 100644
--- a/server/lib/activitypub/process-update.ts
+++ b/server/lib/activitypub/process-update.ts
@@ -50,14 +50,14 @@ async function updateRemoteVideo (account: AccountInstance, videoAttributesToUpd
50 transaction: t 50 transaction: t
51 } 51 }
52 52
53 const videoInstance = await db.Video.loadByUrl(videoAttributesToUpdate.id, t) 53 const videoInstance = await db.Video.loadByUrlAndPopulateAccount(videoAttributesToUpdate.id, t)
54 if (!videoInstance) throw new Error('Video ' + videoAttributesToUpdate.id + ' not found.') 54 if (!videoInstance) throw new Error('Video ' + videoAttributesToUpdate.id + ' not found.')
55 55
56 if (videoInstance.VideoChannel.Account.id !== account.id) { 56 if (videoInstance.VideoChannel.Account.id !== account.id) {
57 throw new Error('Account ' + account.url + ' does not own video channel ' + videoInstance.VideoChannel.url) 57 throw new Error('Account ' + account.url + ' does not own video channel ' + videoInstance.VideoChannel.url)
58 } 58 }
59 59
60 const videoData = await videoActivityObjectToDBAttributes(videoInstance.VideoChannel, videoAttributesToUpdate, t) 60 const videoData = await videoActivityObjectToDBAttributes(videoInstance.VideoChannel, videoAttributesToUpdate)
61 videoInstance.set('name', videoData.name) 61 videoInstance.set('name', videoData.name)
62 videoInstance.set('category', videoData.category) 62 videoInstance.set('category', videoData.category)
63 videoInstance.set('licence', videoData.licence) 63 videoInstance.set('licence', videoData.licence)
diff --git a/server/lib/activitypub/send-request.ts b/server/lib/activitypub/send-request.ts
index f9b72f2a8..d5d07011a 100644
--- a/server/lib/activitypub/send-request.ts
+++ b/server/lib/activitypub/send-request.ts
@@ -24,13 +24,19 @@ async function sendUpdateVideoChannel (videoChannel: VideoChannelInstance, t: Se
24 const videoChannelObject = videoChannel.toActivityPubObject() 24 const videoChannelObject = videoChannel.toActivityPubObject()
25 const data = await updateActivityData(videoChannel.url, videoChannel.Account, videoChannelObject) 25 const data = await updateActivityData(videoChannel.url, videoChannel.Account, videoChannelObject)
26 26
27 return broadcastToFollowers(data, [ videoChannel.Account ], t) 27 const accountsInvolved = await db.VideoChannelShare.loadAccountsByShare(videoChannel.id)
28 accountsInvolved.push(videoChannel.Account)
29
30 return broadcastToFollowers(data, accountsInvolved, t)
28} 31}
29 32
30async function sendDeleteVideoChannel (videoChannel: VideoChannelInstance, t: Sequelize.Transaction) { 33async function sendDeleteVideoChannel (videoChannel: VideoChannelInstance, t: Sequelize.Transaction) {
31 const data = await deleteActivityData(videoChannel.url, videoChannel.Account) 34 const data = await deleteActivityData(videoChannel.url, videoChannel.Account)
32 35
33 return broadcastToFollowers(data, [ videoChannel.Account ], t) 36 const accountsInvolved = await db.VideoChannelShare.loadAccountsByShare(videoChannel.id)
37 accountsInvolved.push(videoChannel.Account)
38
39 return broadcastToFollowers(data, accountsInvolved, t)
34} 40}
35 41
36async function sendAddVideo (video: VideoInstance, t: Sequelize.Transaction) { 42async function sendAddVideo (video: VideoInstance, t: Sequelize.Transaction) {
@@ -44,13 +50,19 @@ async function sendUpdateVideo (video: VideoInstance, t: Sequelize.Transaction)
44 const videoObject = video.toActivityPubObject() 50 const videoObject = video.toActivityPubObject()
45 const data = await updateActivityData(video.url, video.VideoChannel.Account, videoObject) 51 const data = await updateActivityData(video.url, video.VideoChannel.Account, videoObject)
46 52
47 return broadcastToFollowers(data, [ video.VideoChannel.Account ], t) 53 const accountsInvolved = await db.VideoShare.loadAccountsByShare(video.id)
54 accountsInvolved.push(video.VideoChannel.Account)
55
56 return broadcastToFollowers(data, accountsInvolved, t)
48} 57}
49 58
50async function sendDeleteVideo (video: VideoInstance, t: Sequelize.Transaction) { 59async function sendDeleteVideo (video: VideoInstance, t: Sequelize.Transaction) {
51 const data = await deleteActivityData(video.url, video.VideoChannel.Account) 60 const data = await deleteActivityData(video.url, video.VideoChannel.Account)
52 61
53 return broadcastToFollowers(data, [ video.VideoChannel.Account ], t) 62 const accountsInvolved = await db.VideoShare.loadAccountsByShare(video.id)
63 accountsInvolved.push(video.VideoChannel.Account)
64
65 return broadcastToFollowers(data, accountsInvolved, t)
54} 66}
55 67
56async function sendDeleteAccount (account: AccountInstance, t: Sequelize.Transaction) { 68async function sendDeleteAccount (account: AccountInstance, t: Sequelize.Transaction) {