diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-07-10 19:43:21 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-07-10 19:43:21 +0200 |
commit | 4771e0008dd26eadbb7eaff64255a6ec914fdadb (patch) | |
tree | 4fd58f8a3f3c2d674b936c99817b4f5fb958c5d8 /server/helpers | |
parent | 7a214f746bf420defbf17fa218d90d6233551bf8 (diff) | |
download | PeerTube-4771e0008dd26eadbb7eaff64255a6ec914fdadb.tar.gz PeerTube-4771e0008dd26eadbb7eaff64255a6ec914fdadb.tar.zst PeerTube-4771e0008dd26eadbb7eaff64255a6ec914fdadb.zip |
Better typescript typing for a better world
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/requests.ts | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/server/helpers/requests.ts b/server/helpers/requests.ts index 183f6df0d..d67d46044 100644 --- a/server/helpers/requests.ts +++ b/server/helpers/requests.ts | |||
@@ -8,6 +8,7 @@ import { | |||
8 | CONFIG | 8 | CONFIG |
9 | } from '../initializers' | 9 | } from '../initializers' |
10 | import { PodInstance } from '../models' | 10 | import { PodInstance } from '../models' |
11 | import { PodSignature } from '../../shared' | ||
11 | import { sign } from './peertube-crypto' | 12 | import { sign } from './peertube-crypto' |
12 | 13 | ||
13 | type MakeRetryRequestParams = { | 14 | type MakeRetryRequestParams = { |
@@ -37,9 +38,18 @@ type MakeSecureRequestParams = { | |||
37 | } | 38 | } |
38 | function makeSecureRequest (params: MakeSecureRequestParams) { | 39 | function makeSecureRequest (params: MakeSecureRequestParams) { |
39 | return new Promise<{ response: request.RequestResponse, body: any }>((res, rej) => { | 40 | return new Promise<{ response: request.RequestResponse, body: any }>((res, rej) => { |
40 | const requestParams = { | 41 | const requestParams: { |
42 | url: string, | ||
43 | json: { | ||
44 | signature: PodSignature, | ||
45 | data: any | ||
46 | } | ||
47 | } = { | ||
41 | url: REMOTE_SCHEME.HTTP + '://' + params.toPod.host + params.path, | 48 | url: REMOTE_SCHEME.HTTP + '://' + params.toPod.host + params.path, |
42 | json: {} | 49 | json: { |
50 | signature: null, | ||
51 | data: null | ||
52 | } | ||
43 | } | 53 | } |
44 | 54 | ||
45 | if (params.method !== 'POST') { | 55 | if (params.method !== 'POST') { |
@@ -58,14 +68,14 @@ function makeSecureRequest (params: MakeSecureRequestParams) { | |||
58 | } | 68 | } |
59 | 69 | ||
60 | sign(dataToSign).then(signature => { | 70 | sign(dataToSign).then(signature => { |
61 | requestParams.json['signature'] = { | 71 | requestParams.json.signature = { |
62 | host, // Which host we pretend to be | 72 | host, // Which host we pretend to be |
63 | signature | 73 | signature |
64 | } | 74 | } |
65 | 75 | ||
66 | // If there are data informations | 76 | // If there are data informations |
67 | if (params.data) { | 77 | if (params.data) { |
68 | requestParams.json['data'] = params.data | 78 | requestParams.json.data = params.data |
69 | } | 79 | } |
70 | 80 | ||
71 | request.post(requestParams, (err, response, body) => err ? rej(err) : res({ response, body })) | 81 | request.post(requestParams, (err, response, body) => err ? rej(err) : res({ response, body })) |