2018-10-23 11:38:48 +02:00
|
|
|
import { doRequest } from '../../../helpers/requests'
|
|
|
|
import { HTTP_SIGNATURE } from '../../../initializers'
|
|
|
|
import { buildGlobalHeaders } from '../../../lib/job-queue/handlers/utils/activitypub-http-utils'
|
|
|
|
import { activityPubContextify } from '../../../helpers/activitypub'
|
|
|
|
|
2018-11-14 15:01:28 +01:00
|
|
|
function makePOSTAPRequest (url: string, body: any, httpSignature: any, headers: any) {
|
2018-10-23 11:38:48 +02:00
|
|
|
const options = {
|
|
|
|
method: 'POST',
|
|
|
|
uri: url,
|
|
|
|
json: body,
|
|
|
|
httpSignature,
|
|
|
|
headers
|
|
|
|
}
|
|
|
|
|
|
|
|
return doRequest(options)
|
|
|
|
}
|
|
|
|
|
|
|
|
async function makeFollowRequest (to: { url: string }, by: { url: string, privateKey }) {
|
|
|
|
const follow = {
|
|
|
|
type: 'Follow',
|
|
|
|
id: by.url + '/toto',
|
|
|
|
actor: by.url,
|
|
|
|
object: to.url
|
|
|
|
}
|
|
|
|
|
|
|
|
const body = activityPubContextify(follow)
|
|
|
|
|
|
|
|
const httpSignature = {
|
|
|
|
algorithm: HTTP_SIGNATURE.ALGORITHM,
|
|
|
|
authorizationHeaderName: HTTP_SIGNATURE.HEADER_NAME,
|
|
|
|
keyId: by.url,
|
|
|
|
key: by.privateKey,
|
|
|
|
headers: HTTP_SIGNATURE.HEADERS_TO_SIGN
|
|
|
|
}
|
|
|
|
const headers = buildGlobalHeaders(body)
|
|
|
|
|
2018-11-14 15:01:28 +01:00
|
|
|
return makePOSTAPRequest(to.url, body, httpSignature, headers)
|
2018-10-23 11:38:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
2018-11-14 15:01:28 +01:00
|
|
|
makePOSTAPRequest,
|
2018-10-23 11:38:48 +02:00
|
|
|
makeFollowRequest
|
|
|
|
}
|