From 69818c9394366b954b6ba3bd697bd9d2b09f2a16 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Sat, 10 Jun 2017 22:15:25 +0200 Subject: Type functions --- server/helpers/requests.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'server/helpers/requests.ts') 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 { REMOTE_SCHEME, CONFIG } from '../initializers' +import { PodInstance } from '../models' import { sign } from './peertube-crypto' -function makeRetryRequest (params, callback) { +type MakeRetryRequestParams = { + url: string, + method: 'GET'|'POST', + json: Object +} +function makeRetryRequest (params: MakeRetryRequestParams, callback: request.RequestCallback) { replay( request(params, callback), { @@ -20,14 +26,21 @@ function makeRetryRequest (params, callback) { ) } -function makeSecureRequest (params, callback) { +type MakeSecureRequestParams = { + method: 'GET'|'POST' + toPod: PodInstance + path: string + sign: boolean + data?: Object +} +function makeSecureRequest (params: MakeSecureRequestParams, callback: request.RequestCallback) { const requestParams = { url: REMOTE_SCHEME.HTTP + '://' + params.toPod.host + params.path, json: {} } if (params.method !== 'POST') { - return callback(new Error('Cannot make a secure request with a non POST method.')) + return callback(new Error('Cannot make a secure request with a non POST method.'), null, null) } // Add signature if it is specified in the params -- cgit v1.2.3