Change notification when extension is not found (#5184)

* Change notification when extension is not found

- Removes legacy downloadFile and downloadJson in favour of using
  `node-fetch`

- A notification will be displayed if the URL provided results in a
  status of 404

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Resolve PR comments

Signed-off-by: Sebastian Malton <sebastian@malton.name>

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton authored and GitHub committed 2022-10-11 10:40:02 -04:00
1 parent da91347121
commit f021d9d0db
30 files changed
+735 -602

No files matched your search

+6 -6
View File
@@ -6,7 +6,8 @@
// Convert object's keys to camelCase format
import { camelCase } from "lodash";
import type { SingleOrMany } from "./types";
import { isObject } from "./type-narrowing";
import { isObject, isString } from "./type-narrowing";
import * as object from "./objects";
export function toCamelCase<T extends Record<string, unknown>[]>(obj: T): T;
export function toCamelCase<T extends Record<string, unknown>>(obj: T): T;
@@ -17,11 +18,10 @@ export function toCamelCase(obj: SingleOrMany<Record<string, unknown> | unknown>
}
if (isObject(obj)) {
return Object.fromEntries(
Object.entries(obj)
.map(([key, value]) => {
return [camelCase(key), toCamelCase(value)];
}),
return object.fromEntries(
object.entries(obj)
.filter((pair): pair is [string, unknown] => isString(pair[0]))
.map(([key, value]) => [camelCase(key), isObject(value) ? toCamelCase(value) : value]),
);
}
-53
View File
@@ -1,53 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import request from "request";
import type { JsonValue } from "type-fest";
import { parse } from "./json";
export interface DownloadFileOptions {
url: string;
gzip?: boolean;
timeout?: number;
}
export interface DownloadFileTicket<T> {
url: string;
promise: Promise<T>;
cancel(): void;
}
export function downloadFile({ url, timeout, gzip = true }: DownloadFileOptions): DownloadFileTicket<Buffer> {
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 downloadJson(args: DownloadFileOptions): DownloadFileTicket<JsonValue> {
const { promise, ...rest } = downloadFile(args);
return {
promise: promise.then(res => parse(res.toString())),
...rest,
};
}
-1
View File
@@ -14,7 +14,6 @@ export * from "./convertMemory";
export * from "./debouncePromise";
export * from "./delay";
export * from "./disposer";
export * from "./downloadFile";
export * from "./escapeRegExp";
export * from "./formatDuration";
export * from "./getRandId";
+1 -1
View File
@@ -103,7 +103,7 @@ export function isBoolean(val: unknown): val is boolean {
* checks if val is of type object and isn't null
* @param val the value to be checked
*/
export function isObject(val: unknown): val is object {
export function isObject(val: unknown): val is Record<string | symbol | number, unknown> {
return typeof val === "object" && val !== null;
}