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:
Sebastian MaltonandSebastian Malton authored and GitHub committed 2020-09-09 16:41:25 -04:00
1 parent 763b07b7fc
commit 8d1f0efe80
5 files changed
+7 -39

No files matched your search

+1 -11
View File
@@ -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;
}