Fix Tune validation

This commit is contained in:
Piotr Rogowski 2022-10-31 17:20:07 +01:00
parent 89c265e5bb
commit a1dc71691d
No known key found for this signature in database
GPG Key ID: 4A842D702D9C6F8F
2 changed files with 15 additions and 7 deletions

View File

@ -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: '',
};
});
};

View File

@ -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),