From 34ea8a3ab5b13c68b23a4e52375f7d0dedc919f2 Mon Sep 17 00:00:00 2001 From: Daniel James Smith Date: Tue, 8 Mar 2022 13:50:36 +0100 Subject: [PATCH] Fixes for 1pux importer (#501) * Pull jslib * Fixed reading of 1pux files (cherry picked from commit eb0b844750fbdab0926d0ee7ec2bd3618501d1ff) --- jslib | 2 +- src/utils.ts | 37 +++++++++++++++++++++++++------------ 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/jslib b/jslib index 813457c..9aad63f 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 813457c348ef5cac289a4d64d34edc45f49f2b10 +Subproject commit 9aad63f8335354a9b5ea59413bd9e41a68d497a3 diff --git a/src/utils.ts b/src/utils.ts index 37b4f60..deb4085 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -48,19 +48,32 @@ export class CliUtils { } static extract1PuxContent(input: string): Promise { - return new JSZip() - .loadAsync(input) - .then((zip) => { - return zip.file("export.data").async("string"); - }) - .then( - function success(content) { - return content; - }, - function error(e) { - return ""; + return new Promise((resolve, reject) => { + let p: string = null; + if (input != null && input !== "") { + const osInput = path.join(input); + if (osInput.indexOf(path.sep) === -1) { + p = path.join(process.cwd(), osInput); + } else { + p = osInput; } - ); + } else { + reject("You must specify a file path."); + } + fs.readFile(p, function (err, data) { + if (err) { + reject(err); + } + JSZip.loadAsync(data).then( + (zip) => { + resolve(zip.file("export.data").async("string")); + }, + (reason) => { + reject(reason); + } + ); + }); + }); } /** * Save the given data to a file and determine the target file if necessary.