1 import { doRequest } from '../../../server/helpers/requests'
2 import { HTTP_SIGNATURE } from '../../../server/initializers/constants'
3 import { buildGlobalHeaders } from '../../../server/lib/job-queue/handlers/utils/activitypub-http-utils'
4 import { activityPubContextify } from '../../../server/helpers/activitypub'
6 function makePOSTAPRequest (url: string, body: any, httpSignature: any, headers: any) {
8 method: 'POST' as 'POST',
14 return doRequest(url, options)
17 async function makeFollowRequest (to: { url: string }, by: { url: string, privateKey }) {
20 id: by.url + '/' + new Date().getTime(),
25 const body = activityPubContextify(follow)
27 const httpSignature = {
28 algorithm: HTTP_SIGNATURE.ALGORITHM,
29 authorizationHeaderName: HTTP_SIGNATURE.HEADER_NAME,
32 headers: HTTP_SIGNATURE.HEADERS_TO_SIGN
34 const headers = buildGlobalHeaders(body)
36 return makePOSTAPRequest(to.url + '/inbox', body, httpSignature, headers)