aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/jobs
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-24 13:41:10 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:53 +0100
commit63c93323ecdeaa4b6183d75dd3f13469e1ef3ebd (patch)
tree3ee4b351025d4b19f6e880754df44fa7605b683d /server/lib/jobs
parentd4f1e94c89336255537b0b82913591f00e716201 (diff)
downloadPeerTube-63c93323ecdeaa4b6183d75dd3f13469e1ef3ebd.tar.gz
PeerTube-63c93323ecdeaa4b6183d75dd3f13469e1ef3ebd.tar.zst
PeerTube-63c93323ecdeaa4b6183d75dd3f13469e1ef3ebd.zip
Correctly forward like/dislikes and undo
Diffstat (limited to 'server/lib/jobs')
-rw-r--r--server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-broadcast-handler.ts11
-rw-r--r--server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-job-scheduler.ts27
-rw-r--r--server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts10
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 @@
1import { logger } from '../../../helpers' 1import { logger } from '../../../helpers'
2import { buildSignedActivity } from '../../../helpers/activitypub'
3import { doRequest } from '../../../helpers/requests' 2import { doRequest } from '../../../helpers/requests'
4import { database as db } from '../../../initializers' 3import { ActivityPubHttpPayload, computeBody, maybeRetryRequestLater } from './activitypub-http-job-scheduler'
5import { ActivityPubHttpPayload, maybeRetryRequestLater } from './activitypub-http-job-scheduler'
6 4
7async function process (payload: ActivityPubHttpPayload, jobId: number) { 5async 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 @@
1import { JobScheduler, JobHandler } from '../job-scheduler' 1import { JobCategory } from '../../../../shared'
2import { buildSignedActivity } from '../../../helpers/activitypub'
3import { logger } from '../../../helpers/logger'
4import { ACTIVITY_PUB } from '../../../initializers/constants'
5import { database as db } from '../../../initializers/database'
6import { JobHandler, JobScheduler } from '../job-scheduler'
2 7
3import * as activitypubHttpBroadcastHandler from './activitypub-http-broadcast-handler' 8import * as activitypubHttpBroadcastHandler from './activitypub-http-broadcast-handler'
4import * as activitypubHttpUnicastHandler from './activitypub-http-unicast-handler'
5import * as activitypubHttpFetcherHandler from './activitypub-http-fetcher-handler' 9import * as activitypubHttpFetcherHandler from './activitypub-http-fetcher-handler'
6import { JobCategory } from '../../../../shared' 10import * as activitypubHttpUnicastHandler from './activitypub-http-unicast-handler'
7import { ACTIVITY_PUB } from '../../../initializers/constants'
8import { logger } from '../../../helpers/logger'
9 11
10type ActivityPubHttpPayload = { 12type ActivityPubHttpPayload = {
11 uris: string[] 13 uris: string[]
@@ -40,8 +42,21 @@ function maybeRetryRequestLater (err: Error, payload: ActivityPubHttpPayload, ur
40 } 42 }
41} 43}
42 44
45async 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
43export { 57export {
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 @@
1import { logger } from '../../../helpers' 1import { logger } from '../../../helpers'
2import { doRequest } from '../../../helpers/requests' 2import { doRequest } from '../../../helpers/requests'
3import { ActivityPubHttpPayload, maybeRetryRequestLater } from './activitypub-http-job-scheduler' 3import { ActivityPubHttpPayload, computeBody, maybeRetryRequestLater } from './activitypub-http-job-scheduler'
4import { database as db } from '../../../initializers/database'
5import { buildSignedActivity } from '../../../helpers/activitypub'
6 4
7async function process (payload: ActivityPubHttpPayload, jobId: number) { 5async 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 {