]>
Commit | Line | Data |
---|---|---|
2a8c5d0a | 1 | import { doRequest } from '../../../server/helpers/requests' |
74dc3bca | 2 | import { HTTP_SIGNATURE } from '../../../server/initializers/constants' |
2a8c5d0a C |
3 | import { buildGlobalHeaders } from '../../../server/lib/job-queue/handlers/utils/activitypub-http-utils' |
4 | import { activityPubContextify } from '../../../server/helpers/activitypub' | |
df66d815 | 5 | |
5c6d985f | 6 | function makePOSTAPRequest (url: string, body: any, httpSignature: any, headers: any) { |
df66d815 C |
7 | const options = { |
8 | method: 'POST', | |
9 | uri: url, | |
10 | json: body, | |
11 | httpSignature, | |
12 | headers | |
13 | } | |
14 | ||
15 | return doRequest(options) | |
16 | } | |
17 | ||
18 | async function makeFollowRequest (to: { url: string }, by: { url: string, privateKey }) { | |
19 | const follow = { | |
20 | type: 'Follow', | |
21 | id: by.url + '/toto', | |
22 | actor: by.url, | |
23 | object: to.url | |
24 | } | |
25 | ||
26 | const body = activityPubContextify(follow) | |
27 | ||
28 | const httpSignature = { | |
29 | algorithm: HTTP_SIGNATURE.ALGORITHM, | |
30 | authorizationHeaderName: HTTP_SIGNATURE.HEADER_NAME, | |
31 | keyId: by.url, | |
32 | key: by.privateKey, | |
33 | headers: HTTP_SIGNATURE.HEADERS_TO_SIGN | |
34 | } | |
35 | const headers = buildGlobalHeaders(body) | |
36 | ||
5c6d985f | 37 | return makePOSTAPRequest(to.url, body, httpSignature, headers) |
df66d815 C |
38 | } |
39 | ||
40 | export { | |
5c6d985f | 41 | makePOSTAPRequest, |
df66d815 C |
42 | makeFollowRequest |
43 | } |