From a1dc71691d63161d13f318651c8f0745443ee17b Mon Sep 17 00:00:00 2001 From: Piotr Rogowski Date: Mon, 31 Oct 2022 17:20:07 +0100 Subject: [PATCH] Fix Tune validation --- src/pages/Upload.tsx | 14 +++++++++++--- src/utils/tune/TuneParser.ts | 8 ++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/pages/Upload.tsx b/src/pages/Upload.tsx index ae28d84..99acc1b 100644 --- a/src/pages/Upload.tsx +++ b/src/pages/Upload.tsx @@ -319,16 +319,24 @@ const UploadPage = () => { } const parsed = tuneParser.parse(await file.arrayBuffer()); + const { signature } = parsed.getTune().details; + + if (!parsed.isValid()) { + return { + result: false, + message: 'Tune file is not valid or not supported!', + }; + } try { - await fetchINIFile(parsed.getTune().details.signature); + await fetchINIFile(signature); } catch (e) { signatureNotSupportedWarning((e as Error).message); } return { - result: parsed.isValid(), - message: 'Tune file is not valid!', + result: true, + message: '', }; }); }; diff --git a/src/utils/tune/TuneParser.ts b/src/utils/tune/TuneParser.ts index 7b1db95..4cd6a98 100644 --- a/src/utils/tune/TuneParser.ts +++ b/src/utils/tune/TuneParser.ts @@ -23,16 +23,16 @@ class TuneParser { const bibliography = xml.getElementsByTagName('bibliography')[0]?.attributes as any; const versionInfo = xml.getElementsByTagName('versionInfo')[0]?.attributes as any; - if (!xmlPages || !bibliography || !versionInfo) { + if (!xmlPages || !versionInfo) { this.isTuneValid = false; return this; } this.tune.details = { - author: bibliography.author.value, - tuneComment: `${bibliography.tuneComment.value}`.trim(), - writeDate: bibliography.writeDate.value, + author: bibliography ? bibliography.author.value : '', + tuneComment: bibliography ? `${bibliography.tuneComment.value}`.trim() : '', + writeDate: bibliography ? bibliography.writeDate.value : '', fileFormat: versionInfo.fileFormat.value, firmwareInfo: versionInfo.firmwareInfo.value, nPages: Number.parseInt(versionInfo.nPages.value, 2),