Fix:OPF parser crash when no narrators #1578

This commit is contained in:
advplyr 2023-03-05 12:40:21 -06:00
parent aef2c52630
commit 3df7caa838
2 changed files with 3 additions and 3 deletions

View File

@ -296,7 +296,7 @@ class Book {
})
}
} else if (key === 'narrators') {
if (opfMetadata.narrators && opfMetadata.narrators.length && (!this.metadata.narrators.length || opfMetadataOverrideDetails)) {
if (opfMetadata.narrators?.length && (!this.metadata.narrators.length || opfMetadataOverrideDetails)) {
metadataUpdatePayload.narrators = opfMetadata.narrators
}
} else if (key === 'series') {

View File

@ -111,7 +111,7 @@ function fetchVolumeNumber(metadataMeta) {
function fetchNarrators(creators, metadata) {
const narrators = fetchCreators(creators, 'nrt')
if (typeof metadata.meta == "undefined" || narrators.length) return narrators
if (narrators?.length) return narrators
try {
const narratorsJSON = JSON.parse(fetchTagString(metadata.meta, "calibre:user_metadata:#narrators").replace(/"/g, '"'))
return narratorsJSON["#value#"]
@ -150,7 +150,7 @@ module.exports.parseOpfMetadataXML = async (xml) => {
const metadataMeta = prefix ? metadata[`${prefix}:meta`] || metadata.meta : metadata.meta
metadata.meta = {}
if (metadataMeta && metadataMeta.length) {
if (metadataMeta?.length) {
metadataMeta.forEach((meta) => {
if (meta && meta['$'] && meta['$'].name) {
metadata.meta[meta['$'].name] = [meta['$'].content || '']