Fix:Server crash when scanning in invalid epub #2856

This commit is contained in:
advplyr 2024-04-21 15:07:53 -05:00
parent 9102a0045f
commit 359a2752d8

View File

@ -18,7 +18,10 @@ async function extractFileFromEpub(epubPath, filepath) {
Logger.error(`[parseEpubMetadata] Failed to extract ${filepath} from epub at "${epubPath}"`, error)
})
const filedata = data?.toString('utf8')
await zip.close()
await zip.close().catch((error) => {
Logger.error(`[parseEpubMetadata] Failed to close zip`, error)
})
return filedata
}
@ -68,6 +71,9 @@ async function parse(ebookFile) {
Logger.debug(`Parsing metadata from epub at "${epubPath}"`)
// Entrypoint of the epub that contains the filepath to the package document (opf file)
const containerJson = await extractXmlToJson(epubPath, 'META-INF/container.xml')
if (!containerJson) {
return null
}
// Get package document opf filepath from container.xml
const packageDocPath = containerJson.container?.rootfiles?.[0]?.rootfile?.[0]?.$?.['full-path']