From ca0616ce57b858c90994663472dc923b084db09f Mon Sep 17 00:00:00 2001 From: EvilBeaver Date: Fri, 28 Feb 2020 14:24:15 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=9D=D0=B0=D1=81=D1=82=D1=80=D0=BE=D0=B9?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=BF=D1=80=D0=BE=D0=BA=D1=81=D0=B8=20=D0=B2=20?= =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B2=D0=BE=D0=BC=20=D0=BF=D1=80=D0=B8=D0=B1?= =?UTF-8?q?=D0=BB=D0=B8=D0=B6=D0=B5=D0=BD=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 6 ++++++ src/util/downloadUtils.ts | 3 ++- src/util/serverDownloader.ts | 26 +++++++++++++++++++++----- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index a2941924..6d314640 100644 --- a/package.json +++ b/package.json @@ -206,6 +206,11 @@ ], "default": "stable" }, + "language-1c-bsl.languageServerDownloadProxy": { + "description": "Proxy URL for downloading BSL LS binaries", + "type": "string", + "default": "" + }, "language-1c-bsl.languageServerExternalJar": { "description": "Use external bsl-language-server.jar", "type": "boolean", @@ -355,6 +360,7 @@ "request": "^2.88.0", "request-progress": "^3.0.0", "request-promise-native": "^1.0.8", + "https-proxy-agent": "^5.0.0", "semver": "^7.1.1", "vsce": "^1.71.0", "vscode-languageclient": "^6.1.0", diff --git a/src/util/downloadUtils.ts b/src/util/downloadUtils.ts index 33d47de3..e87dbb2c 100644 --- a/src/util/downloadUtils.ts +++ b/src/util/downloadUtils.ts @@ -33,7 +33,8 @@ const requestProgress = require("request-progress"); export function download( srcUrl: string, destPath: fs.PathLike, - progress: (percent: number) => void + progress: (percent: number) => void, + proxySettings: string = null ): Promise { return new Promise((resolve, reject) => { requestProgress(request.get(srcUrl)) diff --git a/src/util/serverDownloader.ts b/src/util/serverDownloader.ts index 928b3f5c..bf2d63ad 100644 --- a/src/util/serverDownloader.ts +++ b/src/util/serverDownloader.ts @@ -36,6 +36,8 @@ import BSLLanguageServerDownloadChannel from "./bsllsDownloadChannel"; import { download } from "./downloadUtils"; import { IGitHubReleasesAPIResponse } from "./githubApi"; import { IStatus } from "./status"; +import * as vscode from "vscode"; +import { LANGUAGE_1C_BSL_CONFIG } from "../const"; const extractZip = promisify(extractZipWithCallback); @@ -56,6 +58,7 @@ export class ServerDownloader { private readonly assetName: string; private readonly installDir: string; private readonly token: string; + private readonly proxySettings: string; constructor( displayName: string, @@ -71,6 +74,12 @@ export class ServerDownloader { this.installDir = installDir; this.assetName = assetName; this.token = token; + + const configuration = vscode.workspace.getConfiguration(LANGUAGE_1C_BSL_CONFIG); + var proxyFromConfig:string = configuration.get("languageServerDownloadProxy"); + if(proxyFromConfig) { + this.proxySettings = proxyFromConfig; + } } public async downloadServerIfNeeded(status: IStatus, channel: BSLLanguageServerDownloadChannel): Promise { @@ -150,7 +159,10 @@ export class ServerDownloader { const rawJsonReleases = await requestPromise.get( `https://api.github.com/repos/${this.githubOrganization}/${this.githubProjectName}/releases`, - { headers } + { + headers, + proxy: this.proxySettings || null + } ); const releases = JSON.parse(rawJsonReleases, jsonDateParser) as IGitHubReleasesAPIResponse[]; @@ -172,7 +184,10 @@ export class ServerDownloader { const rawJson = await requestPromise.get( `https://api.github.com/repos/${this.githubOrganization}/${this.githubProjectName}/releases/${id}`, - { headers } + { + headers, + proxy: this.proxySettings || null + } ); return JSON.parse(rawJson) as IGitHubReleasesAPIResponse; } @@ -211,9 +226,10 @@ export class ServerDownloader { status.update(`Downloading ${this.displayName} ${version}...`); await download(downloadUrl, downloadDest, percent => { status.update( - `Downloading ${this.displayName} ${version} :: ${(percent * 100).toFixed(2)} %` - ); - }); + `Downloading ${this.displayName} ${version} :: ${(percent * 100).toFixed(2)} %`); + }, + this.proxySettings + ); status.update(`Unpacking ${this.displayName} ${version}...`); await extractZip(downloadDest, { dir: path.join(this.installDir, version) }); From 9f6fa737c345966d4806bcbca91535ac59759aec Mon Sep 17 00:00:00 2001 From: EvilBeaver Date: Fri, 28 Feb 2020 14:31:47 +0300 Subject: [PATCH 2/2] =?UTF-8?q?=D0=A4=D0=B0=D0=B9=D0=BB=20=D0=BD=D0=B5=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=BF=D0=B0=D0=BB=20=D0=B2=20=D0=BA=D0=BE=D0=BC?= =?UTF-8?q?=D0=BC=D0=B8=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/util/downloadUtils.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/util/downloadUtils.ts b/src/util/downloadUtils.ts index e87dbb2c..e1198f61 100644 --- a/src/util/downloadUtils.ts +++ b/src/util/downloadUtils.ts @@ -37,7 +37,8 @@ export function download( proxySettings: string = null ): Promise { return new Promise((resolve, reject) => { - requestProgress(request.get(srcUrl)) + var proxiedRq = request.defaults({proxy: proxySettings}) + requestProgress(proxiedRq.get(srcUrl)) .on("progress", state => progress(state.percent)) .on("complete", () => resolve()) .on("error", err => reject(err))