summaryrefslogtreecommitdiff
path: root/extension/src/activation/environmentSetup.ts
diff options
context:
space:
mode:
authorNate Sesti <sestinj@gmail.com>2023-08-04 11:42:47 -0700
committerNate Sesti <sestinj@gmail.com>2023-08-04 11:42:47 -0700
commitfdb036bcecec891adaf99d73101c458fc4087406 (patch)
tree5f39577e92d780c65b4902c8baf0277e7560d49e /extension/src/activation/environmentSetup.ts
parent0db3b14c1f55fab20922acc6bf5e24c19efe8268 (diff)
downloadsncontinue-fdb036bcecec891adaf99d73101c458fc4087406.tar.gz
sncontinue-fdb036bcecec891adaf99d73101c458fc4087406.tar.bz2
sncontinue-fdb036bcecec891adaf99d73101c458fc4087406.zip
fix: :bug: more reliable download with request
Diffstat (limited to 'extension/src/activation/environmentSetup.ts')
-rw-r--r--extension/src/activation/environmentSetup.ts36
1 files changed, 25 insertions, 11 deletions
diff --git a/extension/src/activation/environmentSetup.ts b/extension/src/activation/environmentSetup.ts
index db215e11..ff6fdd66 100644
--- a/extension/src/activation/environmentSetup.ts
+++ b/extension/src/activation/environmentSetup.ts
@@ -9,6 +9,8 @@ import fetch from "node-fetch";
import * as vscode from "vscode";
import * as os from "os";
import fkill from "fkill";
+import { finished } from "stream/promises";
+const request = require("request");
async function runCommand(cmd: string): Promise<[string, string | undefined]> {
var stdout: any = "";
@@ -120,19 +122,31 @@ export async function downloadFromS3(
destination: string,
region: string
) {
- const s3Url = `https://${bucket}.s3.${region}.amazonaws.com/${fileName}`;
- const response = await fetch(s3Url, {
- method: "GET",
- });
- if (!response.ok) {
- const text = await response.text();
- const errText = `Failed to download Continue server from S3: ${text}`;
+ try {
+ ensureDirectoryExistence(destination);
+ const file = fs.createWriteStream(destination);
+ const download = request({
+ url: `https://${bucket}.s3.${region}.amazonaws.com/${fileName}`,
+ });
+
+ download.on("response", (response: any) => {
+ if (response.statusCode !== 200) {
+ throw new Error("No body returned when downloading from S3 bucket");
+ }
+ });
+
+ download.on("error", (err: any) => {
+ fs.unlink(destination, () => {});
+ throw err;
+ });
+
+ download.pipe(file);
+
+ await finished(download);
+ } catch (err: any) {
+ const errText = `Failed to download Continue server from S3: ${err.message}`;
vscode.window.showErrorMessage(errText);
- throw new Error(errText);
}
- const buffer = await response.buffer();
- ensureDirectoryExistence(destination);
- fs.writeFileSync(destination, buffer);
}
export async function startContinuePythonServer() {