aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-07-10 19:43:21 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-07-10 19:43:21 +0200
commit4771e0008dd26eadbb7eaff64255a6ec914fdadb (patch)
tree4fd58f8a3f3c2d674b936c99817b4f5fb958c5d8 /server/helpers
parent7a214f746bf420defbf17fa218d90d6233551bf8 (diff)
downloadPeerTube-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.ts18
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'
10import { PodInstance } from '../models' 10import { PodInstance } from '../models'
11import { PodSignature } from '../../shared'
11import { sign } from './peertube-crypto' 12import { sign } from './peertube-crypto'
12 13
13type MakeRetryRequestParams = { 14type MakeRetryRequestParams = {
@@ -37,9 +38,18 @@ type MakeSecureRequestParams = {
37} 38}
38function makeSecureRequest (params: MakeSecureRequestParams) { 39function 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 }))