2
1

activitypub.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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'
  5. function makePOSTAPRequest (url: string, body: any, httpSignature: any, headers: any) {
  6. const options = {
  7. method: 'POST',
  8. uri: url,
  9. json: body,
  10. httpSignature,
  11. headers
  12. }
  13. return doRequest(options)
  14. }
  15. async function makeFollowRequest (to: { url: string }, by: { url: string, privateKey }) {
  16. const follow = {
  17. type: 'Follow',
  18. id: by.url + '/toto',
  19. actor: by.url,
  20. object: to.url
  21. }
  22. const body = activityPubContextify(follow)
  23. const httpSignature = {
  24. algorithm: HTTP_SIGNATURE.ALGORITHM,
  25. authorizationHeaderName: HTTP_SIGNATURE.HEADER_NAME,
  26. keyId: by.url,
  27. key: by.privateKey,
  28. headers: HTTP_SIGNATURE.HEADERS_TO_SIGN
  29. }
  30. const headers = buildGlobalHeaders(body)
  31. return makePOSTAPRequest(to.url, body, httpSignature, headers)
  32. }
  33. export {
  34. makePOSTAPRequest,
  35. makeFollowRequest
  36. }