aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/helpers/custom-validators/activitypub/announce.ts4
-rw-r--r--server/lib/activitypub/process/process-announce.ts19
-rw-r--r--shared/models/activitypub/activity.ts2
3 files changed, 18 insertions, 7 deletions
diff --git a/server/helpers/custom-validators/activitypub/announce.ts b/server/helpers/custom-validators/activitypub/announce.ts
index 80511129c..469ed5127 100644
--- a/server/helpers/custom-validators/activitypub/announce.ts
+++ b/server/helpers/custom-validators/activitypub/announce.ts
@@ -1,9 +1,11 @@
1import { isBaseActivityValid } from './misc' 1import { isActivityPubUrlValid, isBaseActivityValid } from './misc'
2import { isVideoTorrentCreateActivityValid } from './videos' 2import { isVideoTorrentCreateActivityValid } from './videos'
3 3
4function isAnnounceActivityValid (activity: any) { 4function isAnnounceActivityValid (activity: any) {
5 console.log(activity)
5 return isBaseActivityValid(activity, 'Announce') && 6 return isBaseActivityValid(activity, 'Announce') &&
6 ( 7 (
8 isActivityPubUrlValid(activity.object) ||
7 isVideoTorrentCreateActivityValid(activity.object) 9 isVideoTorrentCreateActivityValid(activity.object)
8 ) 10 )
9} 11}
diff --git a/server/lib/activitypub/process/process-announce.ts b/server/lib/activitypub/process/process-announce.ts
index 7dfee2f60..5568ff538 100644
--- a/server/lib/activitypub/process/process-announce.ts
+++ b/server/lib/activitypub/process/process-announce.ts
@@ -1,4 +1,4 @@
1import { ActivityAnnounce } from '../../../../shared/models/activitypub' 1import { ActivityAnnounce, ActivityCreate } from '../../../../shared/models/activitypub'
2import { logger, retryTransactionWrapper } from '../../../helpers' 2import { logger, retryTransactionWrapper } from '../../../helpers'
3import { sequelizeTypescript } from '../../../initializers' 3import { sequelizeTypescript } from '../../../initializers'
4import { ActorModel } from '../../../models/activitypub/actor' 4import { ActorModel } from '../../../models/activitypub/actor'
@@ -12,7 +12,9 @@ async function processAnnounceActivity (activity: ActivityAnnounce) {
12 const announcedActivity = activity.object 12 const announcedActivity = activity.object
13 const actorAnnouncer = await getOrCreateActorAndServerAndModel(activity.actor) 13 const actorAnnouncer = await getOrCreateActorAndServerAndModel(activity.actor)
14 14
15 if (announcedActivity.type === 'Create' && announcedActivity.object.type === 'Video') { 15 if (typeof announcedActivity === 'string') {
16 return processVideoShare(actorAnnouncer, activity)
17 } else if (announcedActivity.type === 'Create' && announcedActivity.object.type === 'Video') {
16 return processVideoShare(actorAnnouncer, activity) 18 return processVideoShare(actorAnnouncer, activity)
17 } 19 }
18 20
@@ -35,18 +37,25 @@ export {
35function processVideoShare (actorAnnouncer: ActorModel, activity: ActivityAnnounce) { 37function processVideoShare (actorAnnouncer: ActorModel, activity: ActivityAnnounce) {
36 const options = { 38 const options = {
37 arguments: [ actorAnnouncer, activity ], 39 arguments: [ actorAnnouncer, activity ],
38 errorMessage: 'Cannot share the video with many retries.' 40 errorMessage: 'Cannot share the video activity with many retries.'
39 } 41 }
40 42
41 return retryTransactionWrapper(shareVideo, options) 43 return retryTransactionWrapper(shareVideo, options)
42} 44}
43 45
44function shareVideo (actorAnnouncer: ActorModel, activity: ActivityAnnounce) { 46function shareVideo (actorAnnouncer: ActorModel, activity: ActivityAnnounce) {
45 const announcedActivity = activity.object 47 const announced = activity.object
46 48
47 return sequelizeTypescript.transaction(async t => { 49 return sequelizeTypescript.transaction(async t => {
48 // Add share entry 50 // Add share entry
49 const video: VideoModel = await processCreateActivity(announcedActivity) 51 let video: VideoModel
52
53 if (typeof announced === 'string') {
54 video = await VideoModel.loadByUrlAndPopulateAccount(announced as string)
55 if (!video) throw new Error('Unknown video to share ' + announced)
56 } else {
57 video = await processCreateActivity(announced as ActivityCreate)
58 }
50 59
51 const share = { 60 const share = {
52 actorId: actorAnnouncer.id, 61 actorId: actorAnnouncer.id,
diff --git a/shared/models/activitypub/activity.ts b/shared/models/activitypub/activity.ts
index 84f5d851f..d5359eba1 100644
--- a/shared/models/activitypub/activity.ts
+++ b/shared/models/activitypub/activity.ts
@@ -51,7 +51,7 @@ export interface ActivityAccept extends BaseActivity {
51 51
52export interface ActivityAnnounce extends BaseActivity { 52export interface ActivityAnnounce extends BaseActivity {
53 type: 'Announce' 53 type: 'Announce'
54 object: ActivityCreate 54 object: ActivityCreate | string
55} 55}
56 56
57export interface ActivityUndo extends BaseActivity { 57export interface ActivityUndo extends BaseActivity {