diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/helpers/custom-validators/activitypub/announce.ts | 4 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-announce.ts | 19 |
2 files changed, 17 insertions, 6 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 @@ | |||
1 | import { isBaseActivityValid } from './misc' | 1 | import { isActivityPubUrlValid, isBaseActivityValid } from './misc' |
2 | import { isVideoTorrentCreateActivityValid } from './videos' | 2 | import { isVideoTorrentCreateActivityValid } from './videos' |
3 | 3 | ||
4 | function isAnnounceActivityValid (activity: any) { | 4 | function 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 @@ | |||
1 | import { ActivityAnnounce } from '../../../../shared/models/activitypub' | 1 | import { ActivityAnnounce, ActivityCreate } from '../../../../shared/models/activitypub' |
2 | import { logger, retryTransactionWrapper } from '../../../helpers' | 2 | import { logger, retryTransactionWrapper } from '../../../helpers' |
3 | import { sequelizeTypescript } from '../../../initializers' | 3 | import { sequelizeTypescript } from '../../../initializers' |
4 | import { ActorModel } from '../../../models/activitypub/actor' | 4 | import { 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 { | |||
35 | function processVideoShare (actorAnnouncer: ActorModel, activity: ActivityAnnounce) { | 37 | function 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 | ||
44 | function shareVideo (actorAnnouncer: ActorModel, activity: ActivityAnnounce) { | 46 | function 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, |