From d271a1c74cce1ef75672a1ff2888862ee1fc393c Mon Sep 17 00:00:00 2001 From: 0neGal Date: Fri, 18 Feb 2022 22:23:06 +0100 Subject: fix being able to upload any file Usually utils.js would default to simply unzipping whatever was uploaded if it wasn't a folder, now we check if it has "zip" as the extension, case insensitive. If not simply report back the file wasn't a mod. As opposed to the obscure error you got before this. --- src/utils.js | 62 ++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 29 deletions(-) (limited to 'src/utils.js') diff --git a/src/utils.js b/src/utils.js index 1448007..2ea91cd 100644 --- a/src/utils.js +++ b/src/utils.js @@ -544,40 +544,44 @@ const mods = { } try { - fs.createReadStream(mod).pipe(unzip.Extract({path: cache})) - .on("finish", () => { - setTimeout(() => { - let manifest = path.join(cache, "manifest.json"); - if (fs.existsSync(manifest)) { - files = fs.readdirSync(path.join(cache, "mods")); - if (fs.existsSync(path.join(cache, "mods/mod.json"))) { - if (mods.install(path.join(cache, "mods"), require(manifest).name, manifest, true)) { - return true; - } - } else { - for (let i = 0; i < files.length; i++) { - let mod = path.join(cache, "mods", files[i]); - if (fs.statSync(mod).isDirectory()) { - setTimeout(() => { - if (mods.install(mod, false, manifest)) {return true}; - }, 1000) + if (mod.replace(/.*\./, "").toLowerCase() == "zip") { + fs.createReadStream(mod).pipe(unzip.Extract({path: cache})) + .on("finish", () => { + setTimeout(() => { + let manifest = path.join(cache, "manifest.json"); + if (fs.existsSync(manifest)) { + files = fs.readdirSync(path.join(cache, "mods")); + if (fs.existsSync(path.join(cache, "mods/mod.json"))) { + if (mods.install(path.join(cache, "mods"), require(manifest).name, manifest, true)) { + return true; + } + } else { + for (let i = 0; i < files.length; i++) { + let mod = path.join(cache, "mods", files[i]); + if (fs.statSync(mod).isDirectory()) { + setTimeout(() => { + if (mods.install(mod, false, manifest)) {return true}; + }, 1000) + } } - } - if (files.length == 0) { - ipcMain.emit("failedmod"); - return notamod(); + if (files.length == 0) { + ipcMain.emit("failedmod"); + return notamod(); + } } - } - return notamod(); - } + return notamod(); + } - if (mods.install(cache)) { - installed(); - } else {return notamod()} - }, 1000) - }); + if (mods.install(cache)) { + installed(); + } else {return notamod()} + }, 1000) + }); + } else { + return notamod(); + } }catch(err) {return notamod()} } }, -- cgit v1.2.3