]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/extra-utils/requests/activitypub.ts
Fix lint
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / requests / activitypub.ts
CommitLineData
4c7e60bc 1import { activityPubContextify } from '../../../server/helpers/activitypub'
2a8c5d0a 2import { doRequest } from '../../../server/helpers/requests'
74dc3bca 3import { HTTP_SIGNATURE } from '../../../server/initializers/constants'
2a8c5d0a 4import { buildGlobalHeaders } from '../../../server/lib/job-queue/handlers/utils/activitypub-http-utils'
df66d815 5
5c6d985f 6function makePOSTAPRequest (url: string, body: any, httpSignature: any, headers: any) {
df66d815 7 const options = {
db4b15f2 8 method: 'POST' as 'POST',
df66d815
C
9 json: body,
10 httpSignature,
11 headers
12 }
13
db4b15f2 14 return doRequest(url, options)
df66d815
C
15}
16
17async function makeFollowRequest (to: { url: string }, by: { url: string, privateKey }) {
18 const follow = {
19 type: 'Follow',
e7053b1d 20 id: by.url + '/' + new Date().getTime(),
df66d815
C
21 actor: by.url,
22 object: to.url
23 }
24
25 const body = activityPubContextify(follow)
26
27 const httpSignature = {
28 algorithm: HTTP_SIGNATURE.ALGORITHM,
29 authorizationHeaderName: HTTP_SIGNATURE.HEADER_NAME,
30 keyId: by.url,
31 key: by.privateKey,
32 headers: HTTP_SIGNATURE.HEADERS_TO_SIGN
33 }
34 const headers = buildGlobalHeaders(body)
35
e7053b1d 36 return makePOSTAPRequest(to.url + '/inbox', body, httpSignature, headers)
df66d815
C
37}
38
39export {
5c6d985f 40 makePOSTAPRequest,
df66d815
C
41 makeFollowRequest
42}