diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-10 14:34:45 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:40:51 +0100 |
commit | 0d0e8dd0904b380b70e19ebcb4763d65601c4632 (patch) | |
tree | acb625d7c88fbe863fa14bf6783fafe4a8e35137 /server/helpers/requests.ts | |
parent | e4f97babf701481b55cc10fb3448feab5f97c867 (diff) | |
download | PeerTube-0d0e8dd0904b380b70e19ebcb4763d65601c4632.tar.gz PeerTube-0d0e8dd0904b380b70e19ebcb4763d65601c4632.tar.zst PeerTube-0d0e8dd0904b380b70e19ebcb4763d65601c4632.zip |
Continue activitypub
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 | } |