From 47b9ee557ebd2c8cc9141cd5c97f6fd9fd9bd134 Mon Sep 17 00:00:00 2001 From: WarWar Date: Fri, 14 Jul 2023 05:15:29 +0000 Subject: [PATCH 1/4] stop opf importer from adding duplicate info --- server/utils/parsers/parseOpfMetadata.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/server/utils/parsers/parseOpfMetadata.js b/server/utils/parsers/parseOpfMetadata.js index 6788faae..291ed6e1 100644 --- a/server/utils/parsers/parseOpfMetadata.js +++ b/server/utils/parsers/parseOpfMetadata.js @@ -17,7 +17,8 @@ function parseCreators(metadata) { function fetchCreators(creators, role) { if (!creators || !creators.length) return null - return creators.filter(c => c.role === role).map(c => c.value) + const creatorNames = creators.filter(c => c.role === role).map(c => c.value) + return creatorNames.filter((item, index) => creatorNames.indexOf(item) === index) } function fetchTagString(metadata, tag) { @@ -92,7 +93,7 @@ function fetchDescription(metadata) { function fetchGenres(metadata) { if (!metadata['dc:subject'] || !metadata['dc:subject'].length) return [] - return metadata['dc:subject'].map(g => typeof g === 'string' ? g : null).filter(g => !!g) + return metadata['dc:subject'].map(g => typeof g === 'string' ? g : null).filter(g => !!g).filter((item, index) => metadata['dc:subject'].indexOf(item) === index) } function fetchLanguage(metadata) { @@ -122,7 +123,7 @@ function fetchNarrators(creators, metadata) { function fetchTags(metadata) { if (!metadata['dc:tag'] || !metadata['dc:tag'].length) return [] - return metadata['dc:tag'].filter(tag => (typeof tag === 'string')) + return metadata['dc:tag'].filter(tag => (typeof tag === 'string')).filter((item, index) => metadata['dc:tag'].indexOf(item) === index) } function stripPrefix(str) { From 2834f6077e1989ffc6dba4060a1790f9afca984e Mon Sep 17 00:00:00 2001 From: advplyr Date: Sat, 15 Jul 2023 11:41:35 -0500 Subject: [PATCH 2/4] Update server/utils/parsers/parseOpfMetadata.js --- server/utils/parsers/parseOpfMetadata.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/utils/parsers/parseOpfMetadata.js b/server/utils/parsers/parseOpfMetadata.js index 291ed6e1..bd8a33bf 100644 --- a/server/utils/parsers/parseOpfMetadata.js +++ b/server/utils/parsers/parseOpfMetadata.js @@ -17,8 +17,7 @@ function parseCreators(metadata) { function fetchCreators(creators, role) { if (!creators || !creators.length) return null - const creatorNames = creators.filter(c => c.role === role).map(c => c.value) - return creatorNames.filter((item, index) => creatorNames.indexOf(item) === index) + return [...new Set(creators.filter(c => c.role === role).map(c => c.value))] } function fetchTagString(metadata, tag) { From a87c3f2c77a80f7096603aec288eda7a3a8f0eb3 Mon Sep 17 00:00:00 2001 From: advplyr Date: Sat, 15 Jul 2023 11:41:40 -0500 Subject: [PATCH 3/4] Update server/utils/parsers/parseOpfMetadata.js --- server/utils/parsers/parseOpfMetadata.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/utils/parsers/parseOpfMetadata.js b/server/utils/parsers/parseOpfMetadata.js index bd8a33bf..7eaf8f1b 100644 --- a/server/utils/parsers/parseOpfMetadata.js +++ b/server/utils/parsers/parseOpfMetadata.js @@ -92,7 +92,7 @@ function fetchDescription(metadata) { function fetchGenres(metadata) { if (!metadata['dc:subject'] || !metadata['dc:subject'].length) return [] - return metadata['dc:subject'].map(g => typeof g === 'string' ? g : null).filter(g => !!g).filter((item, index) => metadata['dc:subject'].indexOf(item) === index) + return [...new Set(metadata['dc:subject'].filter(g => typeof g === 'string'))] } function fetchLanguage(metadata) { From d181e66d83e5c14ab044f9e9a05a655484c9f606 Mon Sep 17 00:00:00 2001 From: advplyr Date: Sat, 15 Jul 2023 11:41:44 -0500 Subject: [PATCH 4/4] Update server/utils/parsers/parseOpfMetadata.js --- server/utils/parsers/parseOpfMetadata.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/utils/parsers/parseOpfMetadata.js b/server/utils/parsers/parseOpfMetadata.js index 7eaf8f1b..3a34db57 100644 --- a/server/utils/parsers/parseOpfMetadata.js +++ b/server/utils/parsers/parseOpfMetadata.js @@ -122,7 +122,7 @@ function fetchNarrators(creators, metadata) { function fetchTags(metadata) { if (!metadata['dc:tag'] || !metadata['dc:tag'].length) return [] - return metadata['dc:tag'].filter(tag => (typeof tag === 'string')).filter((item, index) => metadata['dc:tag'].indexOf(item) === index) + return [...new Set(metadata['dc:tag'].filter(tag => typeof tag === 'string'))] } function stripPrefix(str) {