diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-16 11:08:25 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:40:52 +0100 |
commit | efc32059d980c51793e8e9ac0fb6a885a8026f94 (patch) | |
tree | c272e63fd57a9625b53dc26ceb1b46aee35d21d3 /server/lib | |
parent | d846501818c2d29e66e6fd141789cb04fd55a437 (diff) | |
download | PeerTube-efc32059d980c51793e8e9ac0fb6a885a8026f94.tar.gz PeerTube-efc32059d980c51793e8e9ac0fb6a885a8026f94.tar.zst PeerTube-efc32059d980c51793e8e9ac0fb6a885a8026f94.zip |
Send server announce when users upload a video
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/activitypub/misc.ts | 6 | ||||
-rw-r--r-- | server/lib/activitypub/process-create.ts | 4 | ||||
-rw-r--r-- | server/lib/activitypub/send-request.ts | 56 | ||||
-rw-r--r-- | server/lib/jobs/transcoding-job-scheduler/video-file-optimizer-handler.ts | 2 | ||||
-rw-r--r-- | server/lib/video-channel.ts | 5 |
5 files changed, 55 insertions, 18 deletions
diff --git a/server/lib/activitypub/misc.ts b/server/lib/activitypub/misc.ts index 2cf0c4fd1..43d26c328 100644 --- a/server/lib/activitypub/misc.ts +++ b/server/lib/activitypub/misc.ts | |||
@@ -28,9 +28,9 @@ async function videoActivityObjectToDBAttributes ( | |||
28 | description: videoObject.content, | 28 | description: videoObject.content, |
29 | channelId: videoChannel.id, | 29 | channelId: videoChannel.id, |
30 | duration: parseInt(duration, 10), | 30 | duration: parseInt(duration, 10), |
31 | createdAt: videoObject.published, | 31 | createdAt: new Date(videoObject.published), |
32 | // FIXME: updatedAt does not seems to be considered by Sequelize | 32 | // FIXME: updatedAt does not seems to be considered by Sequelize |
33 | updatedAt: videoObject.updated, | 33 | updatedAt: new Date(videoObject.updated), |
34 | views: videoObject.views, | 34 | views: videoObject.views, |
35 | likes: 0, | 35 | likes: 0, |
36 | dislikes: 0, | 36 | dislikes: 0, |
@@ -46,7 +46,7 @@ async function videoActivityObjectToDBAttributes ( | |||
46 | 46 | ||
47 | function videoFileActivityUrlToDBAttributes (videoCreated: VideoInstance, videoObject: VideoTorrentObject) { | 47 | function videoFileActivityUrlToDBAttributes (videoCreated: VideoInstance, videoObject: VideoTorrentObject) { |
48 | const fileUrls = videoObject.url | 48 | const fileUrls = videoObject.url |
49 | .filter(u => Object.keys(VIDEO_MIMETYPE_EXT).indexOf(u.mimeType) !== -1) | 49 | .filter(u => Object.keys(VIDEO_MIMETYPE_EXT).indexOf(u.mimeType) !== -1 && u.url.startsWith('video/')) |
50 | 50 | ||
51 | const attributes: VideoFileAttributes[] = [] | 51 | const attributes: VideoFileAttributes[] = [] |
52 | for (const url of fileUrls) { | 52 | for (const url of fileUrls) { |
diff --git a/server/lib/activitypub/process-create.ts b/server/lib/activitypub/process-create.ts index 1b825ebbc..4e4c9f703 100644 --- a/server/lib/activitypub/process-create.ts +++ b/server/lib/activitypub/process-create.ts | |||
@@ -48,8 +48,8 @@ async function addRemoteVideoChannel (account: AccountInstance, videoChannelToCr | |||
48 | name: videoChannelToCreateData.name, | 48 | name: videoChannelToCreateData.name, |
49 | description: videoChannelToCreateData.content, | 49 | description: videoChannelToCreateData.content, |
50 | uuid: videoChannelToCreateData.uuid, | 50 | uuid: videoChannelToCreateData.uuid, |
51 | createdAt: videoChannelToCreateData.published, | 51 | createdAt: new Date(videoChannelToCreateData.published), |
52 | updatedAt: videoChannelToCreateData.updated, | 52 | updatedAt: new Date(videoChannelToCreateData.updated), |
53 | remote: true, | 53 | remote: true, |
54 | accountId: account.id | 54 | accountId: account.id |
55 | } | 55 | } |
diff --git a/server/lib/activitypub/send-request.ts b/server/lib/activitypub/send-request.ts index 1dad51828..664b9d826 100644 --- a/server/lib/activitypub/send-request.ts +++ b/server/lib/activitypub/send-request.ts | |||
@@ -17,46 +17,67 @@ async function sendCreateVideoChannel (videoChannel: VideoChannelInstance, t: Se | |||
17 | const videoChannelObject = videoChannel.toActivityPubObject() | 17 | const videoChannelObject = videoChannel.toActivityPubObject() |
18 | const data = await createActivityData(videoChannel.url, videoChannel.Account, videoChannelObject) | 18 | const data = await createActivityData(videoChannel.url, videoChannel.Account, videoChannelObject) |
19 | 19 | ||
20 | return broadcastToFollowers(data, videoChannel.Account, t) | 20 | return broadcastToFollowers(data, [ videoChannel.Account ], t) |
21 | } | 21 | } |
22 | 22 | ||
23 | async function sendUpdateVideoChannel (videoChannel: VideoChannelInstance, t: Sequelize.Transaction) { | 23 | async function sendUpdateVideoChannel (videoChannel: VideoChannelInstance, t: Sequelize.Transaction) { |
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 | return broadcastToFollowers(data, [ videoChannel.Account ], t) |
28 | } | 28 | } |
29 | 29 | ||
30 | async function sendDeleteVideoChannel (videoChannel: VideoChannelInstance, t: Sequelize.Transaction) { | 30 | async function sendDeleteVideoChannel (videoChannel: VideoChannelInstance, t: Sequelize.Transaction) { |
31 | const data = await deleteActivityData(videoChannel.url, videoChannel.Account) | 31 | const data = await deleteActivityData(videoChannel.url, videoChannel.Account) |
32 | 32 | ||
33 | return broadcastToFollowers(data, videoChannel.Account, t) | 33 | return broadcastToFollowers(data, [ videoChannel.Account ], t) |
34 | } | 34 | } |
35 | 35 | ||
36 | async function sendAddVideo (video: VideoInstance, t: Sequelize.Transaction) { | 36 | async function sendAddVideo (video: VideoInstance, t: Sequelize.Transaction) { |
37 | const videoObject = video.toActivityPubObject() | 37 | const videoObject = video.toActivityPubObject() |
38 | const data = await addActivityData(video.url, video.VideoChannel.Account, video.VideoChannel.url, videoObject) | 38 | const data = await addActivityData(video.url, video.VideoChannel.Account, video.VideoChannel.url, videoObject) |
39 | 39 | ||
40 | return broadcastToFollowers(data, video.VideoChannel.Account, t) | 40 | return broadcastToFollowers(data, [ video.VideoChannel.Account ], t) |
41 | } | 41 | } |
42 | 42 | ||
43 | async function sendUpdateVideo (video: VideoInstance, t: Sequelize.Transaction) { | 43 | async function sendUpdateVideo (video: VideoInstance, t: Sequelize.Transaction) { |
44 | const videoObject = video.toActivityPubObject() | 44 | const videoObject = video.toActivityPubObject() |
45 | const data = await updateActivityData(video.url, video.VideoChannel.Account, videoObject) | 45 | const data = await updateActivityData(video.url, video.VideoChannel.Account, videoObject) |
46 | 46 | ||
47 | return broadcastToFollowers(data, video.VideoChannel.Account, t) | 47 | return broadcastToFollowers(data, [ video.VideoChannel.Account ], t) |
48 | } | 48 | } |
49 | 49 | ||
50 | async function sendDeleteVideo (video: VideoInstance, t: Sequelize.Transaction) { | 50 | async function sendDeleteVideo (video: VideoInstance, t: Sequelize.Transaction) { |
51 | const data = await deleteActivityData(video.url, video.VideoChannel.Account) | 51 | const data = await deleteActivityData(video.url, video.VideoChannel.Account) |
52 | 52 | ||
53 | return broadcastToFollowers(data, video.VideoChannel.Account, t) | 53 | return broadcastToFollowers(data, [ video.VideoChannel.Account ], t) |
54 | } | 54 | } |
55 | 55 | ||
56 | async function sendDeleteAccount (account: AccountInstance, t: Sequelize.Transaction) { | 56 | async function sendDeleteAccount (account: AccountInstance, t: Sequelize.Transaction) { |
57 | const data = await deleteActivityData(account.url, account) | 57 | const data = await deleteActivityData(account.url, account) |
58 | 58 | ||
59 | return broadcastToFollowers(data, account, t) | 59 | return broadcastToFollowers(data, [ account ], t) |
60 | } | ||
61 | |||
62 | async function sendAnnounce (byAccount: AccountInstance, instance: VideoInstance | VideoChannelInstance, t: Sequelize.Transaction) { | ||
63 | const object = instance.toActivityPubObject() | ||
64 | |||
65 | let url = '' | ||
66 | let objectActorUrl: string | ||
67 | if ((instance as any).VideoChannel !== undefined) { | ||
68 | objectActorUrl = (instance as VideoInstance).VideoChannel.Account.url | ||
69 | url = getActivityPubUrl('video', instance.uuid) + '#announce' | ||
70 | } else { | ||
71 | objectActorUrl = (instance as VideoChannelInstance).Account.url | ||
72 | url = getActivityPubUrl('videoChannel', instance.uuid) + '#announce' | ||
73 | } | ||
74 | |||
75 | const objectWithActor = Object.assign(object, { | ||
76 | actor: objectActorUrl | ||
77 | }) | ||
78 | |||
79 | const data = await announceActivityData(url, byAccount, objectWithActor) | ||
80 | return broadcastToFollowers(data, [ byAccount ], t) | ||
60 | } | 81 | } |
61 | 82 | ||
62 | async function sendVideoAbuse ( | 83 | async function sendVideoAbuse ( |
@@ -95,15 +116,17 @@ export { | |||
95 | sendDeleteAccount, | 116 | sendDeleteAccount, |
96 | sendAccept, | 117 | sendAccept, |
97 | sendFollow, | 118 | sendFollow, |
98 | sendVideoAbuse | 119 | sendVideoAbuse, |
120 | sendAnnounce | ||
99 | } | 121 | } |
100 | 122 | ||
101 | // --------------------------------------------------------------------------- | 123 | // --------------------------------------------------------------------------- |
102 | 124 | ||
103 | async function broadcastToFollowers (data: any, fromAccount: AccountInstance, t: Sequelize.Transaction) { | 125 | async function broadcastToFollowers (data: any, toAccountFollowers: AccountInstance[], t: Sequelize.Transaction) { |
104 | const result = await db.AccountFollow.listAcceptedFollowerUrlsForApi(fromAccount.id) | 126 | const toAccountFollowerIds = toAccountFollowers.map(a => a.id) |
127 | const result = await db.AccountFollow.listAcceptedFollowerSharedInboxUrls(toAccountFollowerIds) | ||
105 | if (result.data.length === 0) { | 128 | if (result.data.length === 0) { |
106 | logger.info('Not broadcast because of 0 followers.') | 129 | logger.info('Not broadcast because of 0 followers for %s.', toAccountFollowerIds.join(', ')) |
107 | return | 130 | return |
108 | } | 131 | } |
109 | 132 | ||
@@ -186,6 +209,17 @@ async function addActivityData (url: string, byAccount: AccountInstance, target: | |||
186 | return buildSignedActivity(byAccount, base) | 209 | return buildSignedActivity(byAccount, base) |
187 | } | 210 | } |
188 | 211 | ||
212 | async function announceActivityData (url: string, byAccount: AccountInstance, object: any) { | ||
213 | const base = { | ||
214 | type: 'Announce', | ||
215 | id: url, | ||
216 | actor: byAccount.url, | ||
217 | object | ||
218 | } | ||
219 | |||
220 | return buildSignedActivity(byAccount, base) | ||
221 | } | ||
222 | |||
189 | async function followActivityData (url: string, byAccount: AccountInstance) { | 223 | async function followActivityData (url: string, byAccount: AccountInstance) { |
190 | const base = { | 224 | const base = { |
191 | type: 'Follow', | 225 | type: 'Follow', |
diff --git a/server/lib/jobs/transcoding-job-scheduler/video-file-optimizer-handler.ts b/server/lib/jobs/transcoding-job-scheduler/video-file-optimizer-handler.ts index f6d9627a5..6443899d3 100644 --- a/server/lib/jobs/transcoding-job-scheduler/video-file-optimizer-handler.ts +++ b/server/lib/jobs/transcoding-job-scheduler/video-file-optimizer-handler.ts | |||
@@ -6,6 +6,7 @@ import { VideoInstance } from '../../../models' | |||
6 | import { sendAddVideo } from '../../activitypub/send-request' | 6 | import { sendAddVideo } from '../../activitypub/send-request' |
7 | import { JobScheduler } from '../job-scheduler' | 7 | import { JobScheduler } from '../job-scheduler' |
8 | import { TranscodingJobPayload } from './transcoding-job-scheduler' | 8 | import { TranscodingJobPayload } from './transcoding-job-scheduler' |
9 | import { shareVideoByServer } from '../../../helpers/activitypub' | ||
9 | 10 | ||
10 | async function process (data: TranscodingJobPayload, jobId: number) { | 11 | async function process (data: TranscodingJobPayload, jobId: number) { |
11 | const video = await db.Video.loadByUUIDAndPopulateAccountAndServerAndTags(data.videoUUID) | 12 | const video = await db.Video.loadByUUIDAndPopulateAccountAndServerAndTags(data.videoUUID) |
@@ -37,6 +38,7 @@ async function onSuccess (jobId: number, video: VideoInstance, jobScheduler: Job | |||
37 | 38 | ||
38 | // Now we'll add the video's meta data to our followers | 39 | // Now we'll add the video's meta data to our followers |
39 | await sendAddVideo(video, undefined) | 40 | await sendAddVideo(video, undefined) |
41 | await shareVideoByServer(video, undefined) | ||
40 | 42 | ||
41 | const originalFileHeight = await videoDatabase.getOriginalFileHeight() | 43 | const originalFileHeight = await videoDatabase.getOriginalFileHeight() |
42 | 44 | ||
diff --git a/server/lib/video-channel.ts b/server/lib/video-channel.ts index 80303fb83..e69ec062f 100644 --- a/server/lib/video-channel.ts +++ b/server/lib/video-channel.ts | |||
@@ -5,7 +5,7 @@ import { logger } from '../helpers' | |||
5 | import { AccountInstance } from '../models' | 5 | import { AccountInstance } from '../models' |
6 | import { VideoChannelCreate } from '../../shared/models' | 6 | import { VideoChannelCreate } from '../../shared/models' |
7 | import { sendCreateVideoChannel } from './activitypub/send-request' | 7 | import { sendCreateVideoChannel } from './activitypub/send-request' |
8 | import { getActivityPubUrl } from '../helpers/activitypub' | 8 | import { getActivityPubUrl, shareVideoChannelByServer } from '../helpers/activitypub' |
9 | 9 | ||
10 | async function createVideoChannel (videoChannelInfo: VideoChannelCreate, account: AccountInstance, t: Sequelize.Transaction) { | 10 | async function createVideoChannel (videoChannelInfo: VideoChannelCreate, account: AccountInstance, t: Sequelize.Transaction) { |
11 | const videoChannelData = { | 11 | const videoChannelData = { |
@@ -25,7 +25,8 @@ async function createVideoChannel (videoChannelInfo: VideoChannelCreate, account | |||
25 | // Do not forget to add Account information to the created video channel | 25 | // Do not forget to add Account information to the created video channel |
26 | videoChannelCreated.Account = account | 26 | videoChannelCreated.Account = account |
27 | 27 | ||
28 | sendCreateVideoChannel(videoChannelCreated, t) | 28 | await sendCreateVideoChannel(videoChannelCreated, t) |
29 | await shareVideoChannelByServer(videoChannelCreated, t) | ||
29 | 30 | ||
30 | return videoChannelCreated | 31 | return videoChannelCreated |
31 | } | 32 | } |