diff options
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/activitypub.ts | 9 | ||||
-rw-r--r-- | server/helpers/requests.ts | 4 |
2 files changed, 11 insertions, 2 deletions
diff --git a/server/helpers/activitypub.ts b/server/helpers/activitypub.ts index b0bcfe824..4bf6e387d 100644 --- a/server/helpers/activitypub.ts +++ b/server/helpers/activitypub.ts | |||
@@ -6,6 +6,7 @@ import { ACTIVITY_PUB } from '../initializers' | |||
6 | import { ActorModel } from '../models/activitypub/actor' | 6 | import { ActorModel } from '../models/activitypub/actor' |
7 | import { signJsonLDObject } from './peertube-crypto' | 7 | import { signJsonLDObject } from './peertube-crypto' |
8 | import { pageToStartAndCount } from './core-utils' | 8 | import { pageToStartAndCount } from './core-utils' |
9 | import { parse } from 'url' | ||
9 | 10 | ||
10 | function activityPubContextify <T> (data: T) { | 11 | function activityPubContextify <T> (data: T) { |
11 | return Object.assign(data, { | 12 | return Object.assign(data, { |
@@ -111,9 +112,17 @@ function getActorUrl (activityActor: string | ActivityPubActor) { | |||
111 | return activityActor.id | 112 | return activityActor.id |
112 | } | 113 | } |
113 | 114 | ||
115 | function checkUrlsSameHost (url1: string, url2: string) { | ||
116 | const idHost = parse(url1).host | ||
117 | const actorHost = parse(url2).host | ||
118 | |||
119 | return idHost && actorHost && idHost.toLowerCase() === actorHost.toLowerCase() | ||
120 | } | ||
121 | |||
114 | // --------------------------------------------------------------------------- | 122 | // --------------------------------------------------------------------------- |
115 | 123 | ||
116 | export { | 124 | export { |
125 | checkUrlsSameHost, | ||
117 | getActorUrl, | 126 | getActorUrl, |
118 | activityPubContextify, | 127 | activityPubContextify, |
119 | activityPubCollectionPagination, | 128 | activityPubCollectionPagination, |
diff --git a/server/helpers/requests.ts b/server/helpers/requests.ts index ee9e80404..51facc9e0 100644 --- a/server/helpers/requests.ts +++ b/server/helpers/requests.ts | |||
@@ -3,7 +3,7 @@ import { createWriteStream } from 'fs-extra' | |||
3 | import * as request from 'request' | 3 | import * as request from 'request' |
4 | import { ACTIVITY_PUB } from '../initializers' | 4 | import { ACTIVITY_PUB } from '../initializers' |
5 | 5 | ||
6 | function doRequest ( | 6 | function doRequest <T> ( |
7 | requestOptions: request.CoreOptions & request.UriOptions & { activityPub?: boolean } | 7 | requestOptions: request.CoreOptions & request.UriOptions & { activityPub?: boolean } |
8 | ): Bluebird<{ response: request.RequestResponse, body: any }> { | 8 | ): Bluebird<{ response: request.RequestResponse, body: any }> { |
9 | if (requestOptions.activityPub === true) { | 9 | if (requestOptions.activityPub === true) { |
@@ -11,7 +11,7 @@ function doRequest ( | |||
11 | requestOptions.headers['accept'] = ACTIVITY_PUB.ACCEPT_HEADER | 11 | requestOptions.headers['accept'] = ACTIVITY_PUB.ACCEPT_HEADER |
12 | } | 12 | } |
13 | 13 | ||
14 | return new Bluebird<{ response: request.RequestResponse, body: any }>((res, rej) => { | 14 | return new Bluebird<{ response: request.RequestResponse, body: T }>((res, rej) => { |
15 | request(requestOptions, (err, response, body) => err ? rej(err) : res({ response, body })) | 15 | request(requestOptions, (err, response, body) => err ? rej(err) : res({ response, body })) |
16 | }) | 16 | }) |
17 | } | 17 | } |