Fix Tune validation
This commit is contained in:
parent
89c265e5bb
commit
a1dc71691d
|
@ -319,16 +319,24 @@ const UploadPage = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const parsed = tuneParser.parse(await file.arrayBuffer());
|
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 {
|
try {
|
||||||
await fetchINIFile(parsed.getTune().details.signature);
|
await fetchINIFile(signature);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
signatureNotSupportedWarning((e as Error).message);
|
signatureNotSupportedWarning((e as Error).message);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
result: parsed.isValid(),
|
result: true,
|
||||||
message: 'Tune file is not valid!',
|
message: '',
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -23,16 +23,16 @@ class TuneParser {
|
||||||
const bibliography = xml.getElementsByTagName('bibliography')[0]?.attributes as any;
|
const bibliography = xml.getElementsByTagName('bibliography')[0]?.attributes as any;
|
||||||
const versionInfo = xml.getElementsByTagName('versionInfo')[0]?.attributes as any;
|
const versionInfo = xml.getElementsByTagName('versionInfo')[0]?.attributes as any;
|
||||||
|
|
||||||
if (!xmlPages || !bibliography || !versionInfo) {
|
if (!xmlPages || !versionInfo) {
|
||||||
this.isTuneValid = false;
|
this.isTuneValid = false;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.tune.details = {
|
this.tune.details = {
|
||||||
author: bibliography.author.value,
|
author: bibliography ? bibliography.author.value : '',
|
||||||
tuneComment: `${bibliography.tuneComment.value}`.trim(),
|
tuneComment: bibliography ? `${bibliography.tuneComment.value}`.trim() : '',
|
||||||
writeDate: bibliography.writeDate.value,
|
writeDate: bibliography ? bibliography.writeDate.value : '',
|
||||||
fileFormat: versionInfo.fileFormat.value,
|
fileFormat: versionInfo.fileFormat.value,
|
||||||
firmwareInfo: versionInfo.firmwareInfo.value,
|
firmwareInfo: versionInfo.firmwareInfo.value,
|
||||||
nPages: Number.parseInt(versionInfo.nPages.value, 2),
|
nPages: Number.parseInt(versionInfo.nPages.value, 2),
|
||||||
|
|
Loading…
Reference in New Issue