mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
remove make-syncronous and file-type calls from migration (#844)
* remove make-syncronous and file-type calls from migration Signed-off-by: Sebastian Malton <smalton@mirantis.com> Co-authored-by: Sebastian Malton <smalton@mirantis.com>
This commit is contained in:
1 parent
763b07b7fc
commit
8d1f0efe80
5 files changed
+7
-39
No files matched your search
@@ -33,7 +33,7 @@ describe("empty config", () => {
|
||||
id: "foo",
|
||||
preferences: {
|
||||
terminalCWD: "/tmp",
|
||||
icon: "data:image/jpeg;base64, iVBORw0KGgoAAAANSUhEUgAAA1wAAAKoCAYAAABjkf5",
|
||||
icon: "data:;base64,iVBORw0KGgoAAAANSUhEUgAAA1wAAAKoCAYAAABjkf5",
|
||||
clusterName: "minikube"
|
||||
},
|
||||
kubeConfigPath: ClusterStore.embedCustomKubeConfig("foo", "fancy foo config"),
|
||||
@@ -285,7 +285,7 @@ describe("pre 2.6.0 config with a cluster icon", () => {
|
||||
const storedClusterData = clusterStore.clustersList[0];
|
||||
expect(storedClusterData.hasOwnProperty('icon')).toBe(false);
|
||||
expect(storedClusterData.preferences.hasOwnProperty('icon')).toBe(true);
|
||||
expect(storedClusterData.preferences.icon.startsWith("data:image/jpeg;base64,")).toBe(true);
|
||||
expect(storedClusterData.preferences.icon.startsWith("data:;base64,")).toBe(true);
|
||||
})
|
||||
})
|
||||
|
||||
@@ -364,6 +364,6 @@ describe("pre 3.6.0-beta.1 config with an existing cluster", () => {
|
||||
|
||||
it("migrates to modern format with icon not in file", async () => {
|
||||
const { icon } = clusterStore.clustersList[0].preferences;
|
||||
expect(icon.startsWith("data:image/jpeg;base64, ")).toBe(true);
|
||||
expect(icon.startsWith("data:;base64,")).toBe(true);
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -7,11 +7,6 @@ import { migration } from "../migration-wrapper";
|
||||
import fse from "fs-extra"
|
||||
import { ClusterModel, ClusterStore } from "../../common/cluster-store";
|
||||
import { loadConfig } from "../../common/kube-helpers";
|
||||
import makeSynchronous from "make-synchronous"
|
||||
|
||||
const AsyncFunction = Object.getPrototypeOf(async function () { return }).constructor;
|
||||
const getFileTypeFnString = `return require("file-type").fromBuffer(fileData)`;
|
||||
const getFileType = new AsyncFunction("fileData", getFileTypeFnString);
|
||||
|
||||
export default migration({
|
||||
version: "3.6.0-beta.1",
|
||||
@@ -48,13 +43,8 @@ export default migration({
|
||||
printLog(`migrating ${cluster.preferences.icon} for ${cluster.preferences.clusterName}`)
|
||||
const iconPath = cluster.preferences.icon.replace("store://", "")
|
||||
const fileData = fse.readFileSync(path.join(userDataPath, iconPath));
|
||||
const { mime = "" } = makeSynchronous(getFileType)(fileData);
|
||||
|
||||
if (!mime) {
|
||||
printLog(`mime type not detected for ${cluster.preferences.clusterName}'s icon: ${iconPath}`)
|
||||
}
|
||||
|
||||
cluster.preferences.icon = `data:${mime};base64, ${fileData.toString('base64')}`;
|
||||
cluster.preferences.icon = `data:;base64,${fileData.toString('base64')}`;
|
||||
} else {
|
||||
delete cluster.preferences?.icon;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ export class ClusterIconSetting extends React.Component<Props> {
|
||||
try {
|
||||
if (file) {
|
||||
const buf = Buffer.from(await file.arrayBuffer());
|
||||
cluster.preferences.icon = `data:${file.type};base64, ${buf.toString('base64')}`;
|
||||
cluster.preferences.icon = `data:${file.type};base64,${buf.toString('base64')}`;
|
||||
} else {
|
||||
// this has to be done as a seperate branch (and not always) because `cluster`
|
||||
// is observable and triggers an update loop.
|
||||
@@ -73,4 +73,4 @@ export class ClusterIconSetting extends React.Component<Props> {
|
||||
</>
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user