1
0
Fork 0
peertube/server/lib/job-queue/handlers/utils/activitypub-http-utils.ts
Chocobozzz 94a5ff8a4a
Move job queue to redis
We'll use it as cache in the future.

/!\ You'll loose your old jobs (pending jobs too) so upgrade only when
you don't have pending job anymore.
2018-01-25 18:41:17 +01:00

39 lines
1.1 KiB
TypeScript

import { buildSignedActivity } from '../../../../helpers/activitypub'
import { getServerActor } from '../../../../helpers/utils'
import { ActorModel } from '../../../../models/activitypub/actor'
async function computeBody (payload: { body: any, signatureActorId?: number }) {
let body = payload.body
if (payload.signatureActorId) {
const actorSignature = await ActorModel.load(payload.signatureActorId)
if (!actorSignature) throw new Error('Unknown signature actor id.')
body = await buildSignedActivity(actorSignature, payload.body)
}
return body
}
async function buildSignedRequestOptions (payload: { signatureActorId?: number }) {
let actor: ActorModel
if (payload.signatureActorId) {
actor = await ActorModel.load(payload.signatureActorId)
if (!actor) throw new Error('Unknown signature actor id.')
} else {
// We need to sign the request, so use the server
actor = await getServerActor()
}
const keyId = actor.getWebfingerUrl()
return {
algorithm: 'rsa-sha256',
authorizationHeaderName: 'Signature',
keyId,
key: actor.privateKey
}
}
export {
computeBody,
buildSignedRequestOptions
}