diff options
Diffstat (limited to 'server/lib/jobs')
5 files changed, 41 insertions, 11 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 8040dde2a..3c4d5556f 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,15 +1,17 @@ | |||
1 | import { doRequest, logger } from '../../../helpers' | 1 | import { doRequest, logger } from '../../../helpers' |
2 | import { ActivityPubHttpPayload, computeBody, maybeRetryRequestLater } from './activitypub-http-job-scheduler' | 2 | import { ActivityPubHttpPayload, buildSignedRequestOptions, computeBody, maybeRetryRequestLater } from './activitypub-http-job-scheduler' |
3 | 3 | ||
4 | async function process (payload: ActivityPubHttpPayload, jobId: number) { | 4 | async function process (payload: ActivityPubHttpPayload, jobId: number) { |
5 | logger.info('Processing ActivityPub broadcast in job %d.', jobId) | 5 | logger.info('Processing ActivityPub broadcast in job %d.', jobId) |
6 | 6 | ||
7 | const body = await computeBody(payload) | 7 | const body = await computeBody(payload) |
8 | const httpSignatureOptions = await buildSignedRequestOptions(payload) | ||
8 | 9 | ||
9 | const options = { | 10 | const options = { |
10 | method: 'POST', | 11 | method: 'POST', |
11 | uri: '', | 12 | uri: '', |
12 | json: body | 13 | json: body, |
14 | httpSignature: httpSignatureOptions | ||
13 | } | 15 | } |
14 | 16 | ||
15 | for (const uri of payload.uris) { | 17 | 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 95a5d3ff2..88885cf97 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,5 +1,5 @@ | |||
1 | import { JobCategory } from '../../../../shared' | 1 | import { JobCategory } from '../../../../shared' |
2 | import { buildSignedActivity, logger } from '../../../helpers' | 2 | import { buildSignedActivity, getServerActor, logger } from '../../../helpers' |
3 | import { ACTIVITY_PUB } from '../../../initializers' | 3 | import { ACTIVITY_PUB } from '../../../initializers' |
4 | import { ActorModel } from '../../../models/activitypub/actor' | 4 | import { ActorModel } from '../../../models/activitypub/actor' |
5 | import { JobHandler, JobScheduler } from '../job-scheduler' | 5 | import { JobHandler, JobScheduler } from '../job-scheduler' |
@@ -46,16 +46,36 @@ async function computeBody (payload: ActivityPubHttpPayload) { | |||
46 | 46 | ||
47 | if (payload.signatureActorId) { | 47 | if (payload.signatureActorId) { |
48 | const actorSignature = await ActorModel.load(payload.signatureActorId) | 48 | const actorSignature = await ActorModel.load(payload.signatureActorId) |
49 | if (!actorSignature) throw new Error('Unknown signature account id.') | 49 | if (!actorSignature) throw new Error('Unknown signature actor id.') |
50 | body = await buildSignedActivity(actorSignature, payload.body) | 50 | body = await buildSignedActivity(actorSignature, payload.body) |
51 | } | 51 | } |
52 | 52 | ||
53 | return body | 53 | return body |
54 | } | 54 | } |
55 | 55 | ||
56 | async function buildSignedRequestOptions (payload: ActivityPubHttpPayload) { | ||
57 | let actor: ActorModel | ||
58 | if (payload.signatureActorId) { | ||
59 | actor = await ActorModel.load(payload.signatureActorId) | ||
60 | if (!actor) throw new Error('Unknown signature actor id.') | ||
61 | } else { | ||
62 | // We need to sign the request, so use the server | ||
63 | actor = await getServerActor() | ||
64 | } | ||
65 | |||
66 | const keyId = actor.getWebfingerUrl() | ||
67 | return { | ||
68 | algorithm: 'rsa-sha256', | ||
69 | authorizationHeaderName: 'Signature', | ||
70 | keyId, | ||
71 | key: actor.privateKey | ||
72 | } | ||
73 | } | ||
74 | |||
56 | export { | 75 | export { |
57 | ActivityPubHttpPayload, | 76 | ActivityPubHttpPayload, |
58 | activitypubHttpJobScheduler, | 77 | activitypubHttpJobScheduler, |
59 | maybeRetryRequestLater, | 78 | maybeRetryRequestLater, |
60 | computeBody | 79 | computeBody, |
80 | buildSignedRequestOptions | ||
61 | } | 81 | } |
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 f16cfcec3..7a5caa679 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,16 +1,18 @@ | |||
1 | import { doRequest, logger } from '../../../helpers' | 1 | import { doRequest, logger } from '../../../helpers' |
2 | import { ActivityPubHttpPayload, computeBody, maybeRetryRequestLater } from './activitypub-http-job-scheduler' | 2 | import { ActivityPubHttpPayload, buildSignedRequestOptions, computeBody, maybeRetryRequestLater } from './activitypub-http-job-scheduler' |
3 | 3 | ||
4 | async function process (payload: ActivityPubHttpPayload, jobId: number) { | 4 | async function process (payload: ActivityPubHttpPayload, jobId: number) { |
5 | logger.info('Processing ActivityPub unicast in job %d.', jobId) | 5 | logger.info('Processing ActivityPub unicast in job %d.', jobId) |
6 | 6 | ||
7 | const body = await computeBody(payload) | 7 | const body = await computeBody(payload) |
8 | const httpSignatureOptions = await buildSignedRequestOptions(payload) | ||
8 | 9 | ||
9 | const uri = payload.uris[0] | 10 | const uri = payload.uris[0] |
10 | const options = { | 11 | const options = { |
11 | method: 'POST', | 12 | method: 'POST', |
12 | uri, | 13 | uri, |
13 | json: body | 14 | json: body, |
15 | httpSignature: httpSignatureOptions | ||
14 | } | 16 | } |
15 | 17 | ||
16 | try { | 18 | try { |
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 47b12e66f..d905882be 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 | |||
@@ -1,4 +1,5 @@ | |||
1 | import * as Bluebird from 'bluebird' | 1 | import * as Bluebird from 'bluebird' |
2 | import { VideoPrivacy } from '../../../../shared/models/videos' | ||
2 | import { computeResolutionsToTranscode, logger } from '../../../helpers' | 3 | import { computeResolutionsToTranscode, logger } from '../../../helpers' |
3 | import { sequelizeTypescript } from '../../../initializers' | 4 | import { sequelizeTypescript } from '../../../initializers' |
4 | import { VideoModel } from '../../../models/video/video' | 5 | import { VideoModel } from '../../../models/video/video' |
@@ -35,9 +36,11 @@ async function onSuccess (jobId: number, video: VideoModel, jobScheduler: JobSch | |||
35 | // Video does not exist anymore | 36 | // Video does not exist anymore |
36 | if (!videoDatabase) return undefined | 37 | if (!videoDatabase) return undefined |
37 | 38 | ||
38 | // Now we'll add the video's meta data to our followers | 39 | if (video.privacy !== VideoPrivacy.PRIVATE) { |
39 | await sendCreateVideo(video, undefined) | 40 | // Now we'll add the video's meta data to our followers |
40 | await shareVideoByServerAndChannel(video, undefined) | 41 | await sendCreateVideo(video, undefined) |
42 | await shareVideoByServerAndChannel(video, undefined) | ||
43 | } | ||
41 | 44 | ||
42 | const originalFileHeight = await videoDatabase.getOriginalFileHeight() | 45 | const originalFileHeight = await videoDatabase.getOriginalFileHeight() |
43 | 46 | ||
diff --git a/server/lib/jobs/transcoding-job-scheduler/video-file-transcoder-handler.ts b/server/lib/jobs/transcoding-job-scheduler/video-file-transcoder-handler.ts index 8957b4565..409123bfe 100644 --- a/server/lib/jobs/transcoding-job-scheduler/video-file-transcoder-handler.ts +++ b/server/lib/jobs/transcoding-job-scheduler/video-file-transcoder-handler.ts | |||
@@ -1,4 +1,5 @@ | |||
1 | import { VideoResolution } from '../../../../shared' | 1 | import { VideoResolution } from '../../../../shared' |
2 | import { VideoPrivacy } from '../../../../shared/models/videos' | ||
2 | import { logger } from '../../../helpers' | 3 | import { logger } from '../../../helpers' |
3 | import { VideoModel } from '../../../models/video/video' | 4 | import { VideoModel } from '../../../models/video/video' |
4 | import { sendUpdateVideo } from '../../activitypub/send' | 5 | import { sendUpdateVideo } from '../../activitypub/send' |
@@ -31,7 +32,9 @@ async function onSuccess (jobId: number, video: VideoModel) { | |||
31 | // Video does not exist anymore | 32 | // Video does not exist anymore |
32 | if (!videoDatabase) return undefined | 33 | if (!videoDatabase) return undefined |
33 | 34 | ||
34 | await sendUpdateVideo(video, undefined) | 35 | if (video.privacy !== VideoPrivacy.PRIVATE) { |
36 | await sendUpdateVideo(video, undefined) | ||
37 | } | ||
35 | 38 | ||
36 | return undefined | 39 | return undefined |
37 | } | 40 | } |