mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix changing to got
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
0b98f59f59
commit
07b75b8027
14 files changed
+70
-97
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import requestPromise from "request-promise-native";
|
||||
import got from "got/dist/source";
|
||||
import packageInfo from "../../../package.json";
|
||||
|
||||
export function getAppVersion(): string {
|
||||
@@ -14,11 +14,7 @@ export function getBundledExtensions(): string[] {
|
||||
}
|
||||
|
||||
export async function getAppVersionFromProxyServer(proxyPort: number): Promise<string> {
|
||||
const response = await requestPromise({
|
||||
method: "GET",
|
||||
uri: `http://localhost:${proxyPort}/version`,
|
||||
resolveWithFullResponse: true
|
||||
});
|
||||
const responseJson = await got(`http://localhost:${proxyPort}/version`).json<any>();
|
||||
|
||||
return JSON.parse(response.body).version;
|
||||
return responseJson.version;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from "request";
|
||||
import got, { CancelableRequest } from "got";
|
||||
|
||||
export interface DownloadFileOptions {
|
||||
url: string;
|
||||
@@ -6,32 +6,6 @@ export interface DownloadFileOptions {
|
||||
timeout?: number;
|
||||
}
|
||||
|
||||
export interface DownloadFileTicket {
|
||||
url: string;
|
||||
promise: Promise<Buffer>;
|
||||
cancel(): void;
|
||||
}
|
||||
|
||||
export function downloadFile({ url, timeout, gzip = true }: DownloadFileOptions): DownloadFileTicket {
|
||||
const fileChunks: Buffer[] = [];
|
||||
const req = request(url, { gzip, timeout });
|
||||
const promise: Promise<Buffer> = new Promise((resolve, reject) => {
|
||||
req.on("data", (chunk: Buffer) => {
|
||||
fileChunks.push(chunk);
|
||||
});
|
||||
req.once("error", err => {
|
||||
reject({ url, err });
|
||||
});
|
||||
req.once("complete", () => {
|
||||
resolve(Buffer.concat(fileChunks));
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
url,
|
||||
promise,
|
||||
cancel() {
|
||||
req.abort();
|
||||
}
|
||||
};
|
||||
export function downloadFile({ url, timeout, gzip = true }: DownloadFileOptions): CancelableRequest<Buffer> {
|
||||
return got(url, { timeout, decompress: gzip }).buffer();
|
||||
}
|
||||
Reference in new issue
Block a user