diff options
author | lutangar <johan.dufour@gmail.com> | 2021-11-02 19:11:20 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2021-12-16 10:08:43 +0100 |
commit | 06aad80165d09a8863ab8103149a8ff518b10641 (patch) | |
tree | a97fa31f3ade29ff807ca1b77704eb47085ab99d /server/tests/shared/requests.ts | |
parent | 854f533c12bd2b88c70f9d5aeab770059e9a6861 (diff) | |
download | PeerTube-06aad80165d09a8863ab8103149a8ff518b10641.tar.gz PeerTube-06aad80165d09a8863ab8103149a8ff518b10641.tar.zst PeerTube-06aad80165d09a8863ab8103149a8ff518b10641.zip |
chore(refactor): remove shared folder dependencies to the server
Many files from the `shared` folder were importing files from the `server` folder.
When attempting to use Typescript project references to describe dependencies,
it highlighted a circular dependency beetween `shared` <-> `server`.
The Typescript project forbid such usages.
Using project references greatly improve performance by rebuilding only
the updated project and not all source files.
> see https://www.typescriptlang.org/docs/handbook/project-references.html
Diffstat (limited to 'server/tests/shared/requests.ts')
-rw-r--r-- | server/tests/shared/requests.ts | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/server/tests/shared/requests.ts b/server/tests/shared/requests.ts new file mode 100644 index 000000000..9eb596029 --- /dev/null +++ b/server/tests/shared/requests.ts | |||
@@ -0,0 +1,37 @@ | |||
1 | import { doRequest } from '@server/helpers/requests' | ||
2 | import { activityPubContextify } from '@server/helpers/activitypub' | ||
3 | import { HTTP_SIGNATURE } from '@server/initializers/constants' | ||
4 | import { buildGlobalHeaders } from '@server/lib/job-queue/handlers/utils/activitypub-http-utils' | ||
5 | |||
6 | export function makePOSTAPRequest (url: string, body: any, httpSignature: any, headers: any) { | ||
7 | const options = { | ||
8 | method: 'POST' as 'POST', | ||
9 | json: body, | ||
10 | httpSignature, | ||
11 | headers | ||
12 | } | ||
13 | |||
14 | return doRequest(url, options) | ||
15 | } | ||
16 | |||
17 | export async function makeFollowRequest (to: { url: string }, by: { url: string, privateKey }) { | ||
18 | const follow = { | ||
19 | type: 'Follow', | ||
20 | id: by.url + '/' + new Date().getTime(), | ||
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 | |||
36 | return makePOSTAPRequest(to.url + '/inbox', body, httpSignature, headers) | ||
37 | } | ||