diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-24 13:41:10 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:40:53 +0100 |
commit | 63c93323ecdeaa4b6183d75dd3f13469e1ef3ebd (patch) | |
tree | 3ee4b351025d4b19f6e880754df44fa7605b683d /server/lib/jobs | |
parent | d4f1e94c89336255537b0b82913591f00e716201 (diff) | |
download | PeerTube-63c93323ecdeaa4b6183d75dd3f13469e1ef3ebd.tar.gz PeerTube-63c93323ecdeaa4b6183d75dd3f13469e1ef3ebd.tar.zst PeerTube-63c93323ecdeaa4b6183d75dd3f13469e1ef3ebd.zip |
Correctly forward like/dislikes and undo
Diffstat (limited to 'server/lib/jobs')
3 files changed, 27 insertions, 21 deletions
diff --git a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-broadcast-handler.ts b/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-broadcast-handler.ts index 5b4c65b81..49d4bf5c6 100644 --- a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-broadcast-handler.ts +++ b/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-broadcast-handler.ts | |||
@@ -1,21 +1,16 @@ | |||
1 | import { logger } from '../../../helpers' | 1 | import { logger } from '../../../helpers' |
2 | import { buildSignedActivity } from '../../../helpers/activitypub' | ||
3 | import { doRequest } from '../../../helpers/requests' | 2 | import { doRequest } from '../../../helpers/requests' |
4 | import { database as db } from '../../../initializers' | 3 | import { ActivityPubHttpPayload, computeBody, maybeRetryRequestLater } from './activitypub-http-job-scheduler' |
5 | import { ActivityPubHttpPayload, maybeRetryRequestLater } from './activitypub-http-job-scheduler' | ||
6 | 4 | ||
7 | async function process (payload: ActivityPubHttpPayload, jobId: number) { | 5 | async function process (payload: ActivityPubHttpPayload, jobId: number) { |
8 | logger.info('Processing ActivityPub broadcast in job %d.', jobId) | 6 | logger.info('Processing ActivityPub broadcast in job %d.', jobId) |
9 | 7 | ||
10 | const accountSignature = await db.Account.load(payload.signatureAccountId) | 8 | const body = await computeBody(payload) |
11 | if (!accountSignature) throw new Error('Unknown signature account id.') | ||
12 | |||
13 | const signedBody = await buildSignedActivity(accountSignature, payload.body) | ||
14 | 9 | ||
15 | const options = { | 10 | const options = { |
16 | method: 'POST', | 11 | method: 'POST', |
17 | uri: '', | 12 | uri: '', |
18 | json: signedBody | 13 | json: body |
19 | } | 14 | } |
20 | 15 | ||
21 | for (const uri of payload.uris) { | 16 | for (const uri of payload.uris) { |
diff --git a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-job-scheduler.ts b/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-job-scheduler.ts index ccf109935..f1fe774cc 100644 --- a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-job-scheduler.ts +++ b/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-job-scheduler.ts | |||
@@ -1,11 +1,13 @@ | |||
1 | import { JobScheduler, JobHandler } from '../job-scheduler' | 1 | import { JobCategory } from '../../../../shared' |
2 | import { buildSignedActivity } from '../../../helpers/activitypub' | ||
3 | import { logger } from '../../../helpers/logger' | ||
4 | import { ACTIVITY_PUB } from '../../../initializers/constants' | ||
5 | import { database as db } from '../../../initializers/database' | ||
6 | import { JobHandler, JobScheduler } from '../job-scheduler' | ||
2 | 7 | ||
3 | import * as activitypubHttpBroadcastHandler from './activitypub-http-broadcast-handler' | 8 | import * as activitypubHttpBroadcastHandler from './activitypub-http-broadcast-handler' |
4 | import * as activitypubHttpUnicastHandler from './activitypub-http-unicast-handler' | ||
5 | import * as activitypubHttpFetcherHandler from './activitypub-http-fetcher-handler' | 9 | import * as activitypubHttpFetcherHandler from './activitypub-http-fetcher-handler' |
6 | import { JobCategory } from '../../../../shared' | 10 | import * as activitypubHttpUnicastHandler from './activitypub-http-unicast-handler' |
7 | import { ACTIVITY_PUB } from '../../../initializers/constants' | ||
8 | import { logger } from '../../../helpers/logger' | ||
9 | 11 | ||
10 | type ActivityPubHttpPayload = { | 12 | type ActivityPubHttpPayload = { |
11 | uris: string[] | 13 | uris: string[] |
@@ -40,8 +42,21 @@ function maybeRetryRequestLater (err: Error, payload: ActivityPubHttpPayload, ur | |||
40 | } | 42 | } |
41 | } | 43 | } |
42 | 44 | ||
45 | async function computeBody (payload: ActivityPubHttpPayload) { | ||
46 | let body = payload.body | ||
47 | |||
48 | if (payload.signatureAccountId) { | ||
49 | const accountSignature = await db.Account.load(payload.signatureAccountId) | ||
50 | if (!accountSignature) throw new Error('Unknown signature account id.') | ||
51 | body = await buildSignedActivity(accountSignature, payload.body) | ||
52 | } | ||
53 | |||
54 | return body | ||
55 | } | ||
56 | |||
43 | export { | 57 | export { |
44 | ActivityPubHttpPayload, | 58 | ActivityPubHttpPayload, |
45 | activitypubHttpJobScheduler, | 59 | activitypubHttpJobScheduler, |
46 | maybeRetryRequestLater | 60 | maybeRetryRequestLater, |
61 | computeBody | ||
47 | } | 62 | } |
diff --git a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts b/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts index f7f3dabbd..4c95197c4 100644 --- a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts +++ b/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts | |||
@@ -1,21 +1,17 @@ | |||
1 | import { logger } from '../../../helpers' | 1 | import { logger } from '../../../helpers' |
2 | import { doRequest } from '../../../helpers/requests' | 2 | import { doRequest } from '../../../helpers/requests' |
3 | import { ActivityPubHttpPayload, maybeRetryRequestLater } from './activitypub-http-job-scheduler' | 3 | import { ActivityPubHttpPayload, computeBody, maybeRetryRequestLater } from './activitypub-http-job-scheduler' |
4 | import { database as db } from '../../../initializers/database' | ||
5 | import { buildSignedActivity } from '../../../helpers/activitypub' | ||
6 | 4 | ||
7 | async function process (payload: ActivityPubHttpPayload, jobId: number) { | 5 | async function process (payload: ActivityPubHttpPayload, jobId: number) { |
8 | logger.info('Processing ActivityPub unicast in job %d.', jobId) | 6 | logger.info('Processing ActivityPub unicast in job %d.', jobId) |
9 | 7 | ||
10 | const accountSignature = await db.Account.load(payload.signatureAccountId) | 8 | const body = await computeBody(payload) |
11 | if (!accountSignature) throw new Error('Unknown signature account id.') | ||
12 | 9 | ||
13 | const signedBody = await buildSignedActivity(accountSignature, payload.body) | ||
14 | const uri = payload.uris[0] | 10 | const uri = payload.uris[0] |
15 | const options = { | 11 | const options = { |
16 | method: 'POST', | 12 | method: 'POST', |
17 | uri, | 13 | uri, |
18 | json: signedBody | 14 | json: body |
19 | } | 15 | } |
20 | 16 | ||
21 | try { | 17 | try { |