From 3df7caa83823a7937e22dce22e21885380ce179a Mon Sep 17 00:00:00 2001 From: advplyr Date: Sun, 5 Mar 2023 12:40:21 -0600 Subject: [PATCH] Fix:OPF parser crash when no narrators #1578 --- server/objects/mediaTypes/Book.js | 2 +- server/utils/parsers/parseOpfMetadata.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/server/objects/mediaTypes/Book.js b/server/objects/mediaTypes/Book.js index 3fa4c1be..b25938ca 100644 --- a/server/objects/mediaTypes/Book.js +++ b/server/objects/mediaTypes/Book.js @@ -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') { diff --git a/server/utils/parsers/parseOpfMetadata.js b/server/utils/parsers/parseOpfMetadata.js index f51a7e93..6788faae 100644 --- a/server/utils/parsers/parseOpfMetadata.js +++ b/server/utils/parsers/parseOpfMetadata.js @@ -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 || '']