Ver Fonte

特殊图片处理

john há 7 meses atrás
pai
commit
67f264a085

+ 45 - 0
epub_node/db/book.js

@@ -0,0 +1,45 @@
+import connection from "./base.js";
+
+export async function book_mate_insert({
+  book_name = "",
+  book_id = "",
+  book_md5 = "",
+  language = "",
+  date = null,
+  creatorFileAs = "",
+  UUID = "",
+  ISBN = "",
+  author_id = "",
+  category_id = "",
+  Introduction = "",
+}) {
+  const sql = `
+    INSERT INTO book (book_name, book_id, book_md5, language, date, creatorFileAs, UUID, ISBN, author_id, category_id, Introduction)
+    VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
+    ON DUPLICATE KEY UPDATE book_id = book_id;
+  `;
+  const values = [
+    book_name,
+    book_id,
+    book_md5,
+    language,
+    date,
+    creatorFileAs,
+    UUID,
+    ISBN,
+    author_id,
+    category_id,
+    Introduction,
+  ];
+
+  return new Promise((resolve, reject) => {
+    connection.execute(sql, values, (error, result) => {
+      if (error) {
+        console.error('Database error:', error);
+        return reject(error); // 使用 reject 处理错误
+      }
+      resolve(result); // 返回查询结果
+    });
+  });
+}
+

+ 5 - 5
epub_node/db/files.js

@@ -40,11 +40,11 @@ export async function files_insert_link_epub({
   book_id = "",
   author_id = "",
 }) {
-  console.log("files_insert_link_epub", {
-    file_id,
-    book_id,
-    author_id,
-  });
+  // console.log("files_insert_link_epub", {
+  //   file_id,
+  //   book_id,
+  //   author_id,
+  // });
 
   return new Promise(async (resolve, reject) => {
     try {

+ 2 - 1
epub_node/db/index.js

@@ -1,3 +1,4 @@
 
 export * from './files.js'
-export * from './author.js'
+export * from './author.js'
+export * from './book.js'

+ 3 - 18
epub_node/router/epub/index.js

@@ -14,7 +14,7 @@ import { v4 as uuidv4 } from "uuid";
 import { dirExists, isFileSync, isDir, waittime } from "#utils";
 
 import { saveImgs, calculateMD5 } from "./image.js";
-import { htmlParser } from "./txt.js";
+import { htmlParser, saveMateInfo } from "./txt.js";
 import { saveAllCSS } from "./style.js";
 
 const router = express.Router();
@@ -166,27 +166,12 @@ router.put("/", async function (req, res) {
     3、存储html数据
     4、存储css数据
    */
+  await saveMateInfo(epub, uploadPath, file_md5, author_id)
   await saveImgs(epub, uploadPath, file_md5, author_id);
   await saveAllCSS(epub, uploadPath, file_md5, author_id);
   // 存储html数据
   await htmlParser(epub, zipEpubExtract, file_md5, author_id);
-
-  // console.log("\nSPINE:\n");
-  // // console.log(epub.flow);
-  // epub.flow.forEach((elm) => {
-  //   if (elm.href.indexOf("html") < 0) {
-  //     console.log(88, elm);
-  //   }
-  // });
-
-  // console.log("\nTOC:\n");
-  // console.log(epub.toc);
-
-  // epub.toc.forEach((elm) => {
-  //   if (elm.href.indexOf("html") < 0) {
-  //     console.log(88, elm);
-  //   }
-  // });
+  console.log('书籍处理完毕')
 });
 
 export default router;

+ 30 - 2
epub_node/router/epub/txt.js

@@ -6,19 +6,27 @@ import {
   searchFileByPath,
   files_insert_link_epub,
   files_insert,
+  book_mate_insert,
 } from "#db";
 import { calculateMD5 } from "./image.js";
 
-const imageExtensions = [".png", ".jpg", ".jpeg"];
+const imageExtensions = [".png", ".jpg", ".jpeg", ".svg"];
 
 async function processFiles(elmData, file_md5) {
   const rows = elmData.toString().split(/\n/);
   const promises = rows.map(async (rowtext) => {
+    if (rowtext.indexOf(".svg") > -1) {
+      console.log(191919, rowtext);
+    }
     if (
       rowtext.includes("Images") &&
       imageExtensions.some((ext) => rowtext.includes(ext))
     ) {
-      const match = rowtext.match(/.*(..\/Images\/(.*\.(jpg|png|jpeg))).*/);
+      const match = rowtext.match(/.*(..\/Images\/(.*\.(jpg|png|jpeg|svg))).*/);
+      if (rowtext.indexOf(".svg") > -1) {
+        console.log(2323, match, rowtext);
+      }
+
       if (match) {
         const [, imgPath, imageSrc] = match;
         const imgRow = await searchFileByPath(imageSrc);
@@ -91,3 +99,23 @@ export async function htmlParser(epub, zipEpubExtract, file_md5, author_id) {
     })
   );
 }
+
+// saveMateInfo
+export async function saveMateInfo(epub, zipEpubExtract, file_md5, author_id) {
+  // book_mate_insert
+  const params = {
+    book_name: epub.metadata.title,
+    book_id: file_md5,
+    book_md5: file_md5,
+    // language: "",
+    // date: "",
+    // creatorFileAs: "",
+    // UUID: "",
+    // ISBN: "",
+    author_id: author_id,
+    // category_id: "",
+    // Introduction: "",
+  };
+
+  const res = await book_mate_insert(params);
+}