Skip to content

Commit

Permalink
Fix:Server crash when scanning in invalid epub #2856
Browse files Browse the repository at this point in the history
  • Loading branch information
advplyr committed Apr 21, 2024
1 parent 9102a00 commit 359a275
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion server/utils/parsers/parseEpubMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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']
Expand Down

0 comments on commit 359a275

Please sign in to comment.