aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/requests.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-10 14:34:45 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:51 +0100
commit0d0e8dd0904b380b70e19ebcb4763d65601c4632 (patch)
treeacb625d7c88fbe863fa14bf6783fafe4a8e35137 /server/helpers/requests.ts
parente4f97babf701481b55cc10fb3448feab5f97c867 (diff)
downloadPeerTube-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.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}