aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/requests.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/requests.ts')
-rw-r--r--server/helpers/requests.ts11
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 {
10import { PodInstance } from '../models' 10import { PodInstance } from '../models'
11import { PodSignature } from '../../shared' 11import { PodSignature } from '../../shared'
12import { signObject } from './peertube-crypto' 12import { signObject } from './peertube-crypto'
13import { createWriteStream } from 'fs'
13 14
14function doRequest (requestOptions: request.CoreOptions & request.UriOptions) { 15function 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
21function 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
20type MakeRetryRequestParams = { 30type 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
89export { 99export {
90 doRequest, 100 doRequest,
101 doRequestAndSaveToFile,
91 makeRetryRequest, 102 makeRetryRequest,
92 makeSecureRequest 103 makeSecureRequest
93} 104}