From a58adbb99f5e3283f495e8aa9db6f7b84e02592b Mon Sep 17 00:00:00 2001
From: lyg <1543117173@qq.com>
Date: 星期六, 15 六月 2024 14:20:30 +0800
Subject: [PATCH] PDF页数获取出错处理

---
 src/main.mjs |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/main.mjs b/src/main.mjs
index 6f0a8eb..f8ec1c0 100644
--- a/src/main.mjs
+++ b/src/main.mjs
@@ -43,7 +43,7 @@
  */
 async function getPdfPages(filepath) {
   const buf = fs.readFileSync(filepath);
-  const pdfDoc = await pdfLib.PDFDocument.load(buf);
+  const pdfDoc = await pdfLib.PDFDocument.load(buf, { ignoreEncryption: true });
   const pages = pdfDoc.getPages().length;
   return pages;
 }
@@ -344,7 +344,7 @@
           book.format = ext;
           book.file = filepath;
           book.url = url;
-          book.pages = await getPdfPages(filepath);
+          book.pages = await getPdfPages(filepath).catch(e => 0);
           resolve(true);
         });
         stream.on("error", (err) => {

--
Gitblit v1.9.1