diff options
Diffstat (limited to 'server/helpers/requests.ts')
-rw-r--r-- | server/helpers/requests.ts | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/server/helpers/requests.ts b/server/helpers/requests.ts index 8c4c983f7..31cedd768 100644 --- a/server/helpers/requests.ts +++ b/server/helpers/requests.ts | |||
@@ -10,6 +10,7 @@ import { | |||
10 | import { PodInstance } from '../models' | 10 | import { PodInstance } from '../models' |
11 | import { PodSignature } from '../../shared' | 11 | import { PodSignature } from '../../shared' |
12 | import { signObject } from './peertube-crypto' | 12 | import { signObject } from './peertube-crypto' |
13 | import { createWriteStream } from 'fs' | ||
13 | 14 | ||
14 | function doRequest (requestOptions: request.CoreOptions & request.UriOptions) { | 15 | function doRequest (requestOptions: request.CoreOptions & request.UriOptions) { |
15 | return new Promise<{ response: request.RequestResponse, body: any }>((res, rej) => { | 16 | return new Promise<{ response: request.RequestResponse, body: any }>((res, rej) => { |
@@ -17,6 +18,15 @@ function doRequest (requestOptions: request.CoreOptions & request.UriOptions) { | |||
17 | }) | 18 | }) |
18 | } | 19 | } |
19 | 20 | ||
21 | function doRequestAndSaveToFile (requestOptions: request.CoreOptions & request.UriOptions, destPath: string) { | ||
22 | return new Promise<request.RequestResponse>((res, rej) => { | ||
23 | request(requestOptions) | ||
24 | .on('response', response => res(response as request.RequestResponse)) | ||
25 | .on('error', err => rej(err)) | ||
26 | .pipe(createWriteStream(destPath)) | ||
27 | }) | ||
28 | } | ||
29 | |||
20 | type MakeRetryRequestParams = { | 30 | type MakeRetryRequestParams = { |
21 | url: string, | 31 | url: string, |
22 | method: 'GET' | 'POST', | 32 | method: 'GET' | 'POST', |
@@ -88,6 +98,7 @@ function makeSecureRequest (params: MakeSecureRequestParams) { | |||
88 | 98 | ||
89 | export { | 99 | export { |
90 | doRequest, | 100 | doRequest, |
101 | doRequestAndSaveToFile, | ||
91 | makeRetryRequest, | 102 | makeRetryRequest, |
92 | makeSecureRequest | 103 | makeSecureRequest |
93 | } | 104 | } |