diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-06-10 22:15:25 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-06-10 22:15:25 +0200 |
commit | 69818c9394366b954b6ba3bd697bd9d2b09f2a16 (patch) | |
tree | ad199a18ec3c322460d6f9523fc383ee562554e0 /server/helpers/requests.ts | |
parent | 4d4e5cd4dca78480ec7f40e747f424cd107376a4 (diff) | |
download | PeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.tar.gz PeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.tar.zst PeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.zip |
Type functions
Diffstat (limited to 'server/helpers/requests.ts')
-rw-r--r-- | server/helpers/requests.ts | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/server/helpers/requests.ts b/server/helpers/requests.ts index 48b1fd703..b40fc8e39 100644 --- a/server/helpers/requests.ts +++ b/server/helpers/requests.ts | |||
@@ -6,9 +6,15 @@ import { | |||
6 | REMOTE_SCHEME, | 6 | REMOTE_SCHEME, |
7 | CONFIG | 7 | CONFIG |
8 | } from '../initializers' | 8 | } from '../initializers' |
9 | import { PodInstance } from '../models' | ||
9 | import { sign } from './peertube-crypto' | 10 | import { sign } from './peertube-crypto' |
10 | 11 | ||
11 | function makeRetryRequest (params, callback) { | 12 | type MakeRetryRequestParams = { |
13 | url: string, | ||
14 | method: 'GET'|'POST', | ||
15 | json: Object | ||
16 | } | ||
17 | function makeRetryRequest (params: MakeRetryRequestParams, callback: request.RequestCallback) { | ||
12 | replay( | 18 | replay( |
13 | request(params, callback), | 19 | request(params, callback), |
14 | { | 20 | { |
@@ -20,14 +26,21 @@ function makeRetryRequest (params, callback) { | |||
20 | ) | 26 | ) |
21 | } | 27 | } |
22 | 28 | ||
23 | function makeSecureRequest (params, callback) { | 29 | type MakeSecureRequestParams = { |
30 | method: 'GET'|'POST' | ||
31 | toPod: PodInstance | ||
32 | path: string | ||
33 | sign: boolean | ||
34 | data?: Object | ||
35 | } | ||
36 | function makeSecureRequest (params: MakeSecureRequestParams, callback: request.RequestCallback) { | ||
24 | const requestParams = { | 37 | const requestParams = { |
25 | url: REMOTE_SCHEME.HTTP + '://' + params.toPod.host + params.path, | 38 | url: REMOTE_SCHEME.HTTP + '://' + params.toPod.host + params.path, |
26 | json: {} | 39 | json: {} |
27 | } | 40 | } |
28 | 41 | ||
29 | if (params.method !== 'POST') { | 42 | if (params.method !== 'POST') { |
30 | return callback(new Error('Cannot make a secure request with a non POST method.')) | 43 | return callback(new Error('Cannot make a secure request with a non POST method.'), null, null) |
31 | } | 44 | } |
32 | 45 | ||
33 | // Add signature if it is specified in the params | 46 | // Add signature if it is specified in the params |