浏览代码

处理默认资源

john 7 月之前
父节点
当前提交
ef83d1decc

+ 17 - 11
epub_node/db/DB.sql

@@ -68,16 +68,21 @@ CREATE TABLE `style_link_book` (
 
 -- epub_manage.chapter definition
 CREATE TABLE `chapter` (
-  `id` INT NOT NULL AUTO_INCREMENT,
-  `name` VARCHAR(255) NOT NULL,  -- 将 name 长度调整为 255
-  `book_id` VARCHAR(100) NOT NULL,  -- book_id 长度为 100
-  `author_id` VARCHAR(100) NOT NULL,  -- author_id 长度为 100
-  `content` LONGTEXT DEFAULT NULL,
-  `create_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
-  `update_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
-  PRIMARY KEY (`id`),
-  CONSTRAINT `fk_chapter_book` FOREIGN KEY (`book_id`) REFERENCES `book`(`book_id`) ON DELETE CASCADE,  -- 外键约束
-  CONSTRAINT `fk_chapter_author` FOREIGN KEY (`author_id`) REFERENCES `author`(`author_id`) ON DELETE CASCADE -- 外键约束
+    `id` INT NOT NULL AUTO_INCREMENT,
+    `name` VARCHAR(255) NOT NULL,  -- Chapter name with a maximum length of 255 characters
+    `book_id` VARCHAR(100) NOT NULL,  -- Book ID with a maximum length of 100 characters
+    `author_id` VARCHAR(100) NOT NULL,  -- Author ID with a maximum length of 100 characters
+    `content` LONGTEXT DEFAULT NULL,  -- Chapter content
+    `level` INT NULL,  -- Level of the chapter, can be NULL
+    `order_index` INT NULL,  -- Order index for sorting chapters, can be NULL
+    `order_id` VARCHAR(255) NULL,  -- Order ID, can be NULL
+    `old_path` VARCHAR(255) NULL,  -- Old path, can be NULL
+    `path` VARCHAR(255) NULL,  -- Current path, can be NULL
+    `create_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,  -- Creation timestamp
+    `update_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,  -- Update timestamp
+    PRIMARY KEY (`id`),
+    CONSTRAINT `fk_chapter_book` FOREIGN KEY (`book_id`) REFERENCES `book`(`book_id`) ON DELETE CASCADE,  -- Foreign key constraint for book
+    CONSTRAINT `fk_chapter_author` FOREIGN KEY (`author_id`) REFERENCES `author`(`author_id`) ON DELETE CASCADE  -- Foreign key constraint for author
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
 
 
@@ -90,6 +95,7 @@ CREATE TABLE `files` (
   `size` INT NOT NULL,
   `name` VARCHAR(255) DEFAULT NULL,
   `path` VARCHAR(255) DEFAULT NULL,
+  `source_id` VARCHAR(100) DEFAULT NULL,
   `create_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
   `update_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
   PRIMARY KEY (`id`),
@@ -109,4 +115,4 @@ CREATE TABLE `book_link_file` (
   CONSTRAINT `fk_book_file` FOREIGN KEY (`file_id`) REFERENCES `files`(`file_id`) ON DELETE CASCADE,  -- 外键约束
   CONSTRAINT `fk_link_book` FOREIGN KEY (`book_id`) REFERENCES `book`(`book_id`) ON DELETE CASCADE,  -- 外键约束
   CONSTRAINT `fk_link_author` FOREIGN KEY (`author_id`) REFERENCES `author`(`author_id`) ON DELETE CASCADE -- 外键约束
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

+ 70 - 0
epub_node/db/chapter.js

@@ -0,0 +1,70 @@
+import connection from "./base.js";
+
+
+/*
+*  `name` VARCHAR(255) NOT NULL,  -- Chapter name with a maximum length of 255 characters
+    `book_id` VARCHAR(100) NOT NULL,  -- Book ID with a maximum length of 100 characters
+    `author_id` VARCHAR(100) NOT NULL,  -- Author ID with a maximum length of 100 characters
+    `content` LONGTEXT DEFAULT NULL,  -- Chapter content
+    `level` INT NULL,  -- Level of the chapter, can be NULL
+    `order_index` INT NULL,  -- Order index for sorting chapters, can be NULL
+    `order_id` VARCHAR(255) NULL,  -- Order ID, can be NULL
+    `old_path` VARCHAR(255) NULL,  -- Old path, can be NULL
+    `path` VARCHAR(255) NULL,  -- Current path, can be NULL
+    * */
+export async function chapter_insert({
+                                         name = "",
+                                         book_id = "",
+                                         author_id = "",
+                                         content = "",
+                                         level = '',
+                                         order_index = "",
+                                         order_id = "",
+                                         old_path = "",
+                                         path = "",
+                                     }) {
+    const sql = `
+        INSERT INTO chapter (name, book_id, author_id, content, level, order_index, order_id, old_path, path)
+        VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);
+    `;
+    const values = [
+        name, book_id, author_id, content, level, order_index, order_id, old_path, path,
+    ];
+    
+    return new Promise((resolve, reject) => {
+        connection.execute(sql, values, (error, result) => {
+            if (error) {
+                console.error('Database error:', error);
+                return reject(error); // 使用 reject 处理错误
+            }
+            resolve(result); // 返回查询结果
+        });
+    });
+}
+
+
+/*根据文件路径查询章节数据*/
+
+// select * from files where source_id like '%part0042%'
+export async function searchChapterInfoForPath(path, book_id) {
+    return new Promise((resolve, reject) => {
+        const query = `
+            SELECT files.file_id
+            FROM files
+                     INNER JOIN book_link_file ON files.file_id = book_link_file.file_id
+            WHERE book_link_file.book_id = ?
+              AND files.source_id LIKE ?;`; // 确保 `source_id` 上有索引
+        
+        // 调整参数顺序以匹配 SQL 中的占位符顺序
+        const queryParams = [book_id, `%${path}%`];
+        
+        connection.query(query, queryParams, (err, rows) => {
+            if (err) {
+                return reject(err);
+            }
+            
+            resolve(rows.length > 0 ? rows[0] : false);
+        });
+    });
+}
+

+ 109 - 83
epub_node/db/files.js

@@ -10,99 +10,125 @@ import connection from "./base.js";
 
   */
 export async function files_insert({
-  file_id = "",
-  source_id = "",
-  md5 = "",
-  mimetype = "",
-  size = "",
-  name = "",
-  path = "",
-}) {
-  return new Promise(async (resolve, reject) => {
-    try {
-      const sql = `
-          INSERT INTO files (file_id, source_id, md5, mimetype, size, name, path)
-          VALUES (?, ?, ?, ?, ?, ?, ?)
-          ON DUPLICATE KEY UPDATE file_id = file_id;
-        `;
-      const values = [file_id, source_id, md5, mimetype, size, name, path];
-      // 直接接收 execute 返回的内容
-      const result = await connection.execute(sql, values);
-      return resolve(result);
-    } catch (err) {
-      return resolve(false);
-    }
-  });
+                                       file_id = "",
+                                       source_id = "",
+                                       md5 = "",
+                                       mimetype = "",
+                                       size = "",
+                                       name = "",
+                                       path = "",
+                                   }) {
+    return new Promise(async (resolve, reject) => {
+        try {
+            const sql = `
+                INSERT INTO files (file_id, source_id, md5, mimetype, size, name, path)
+                VALUES (?, ?, ?, ?, ?, ?, ?) ON DUPLICATE KEY
+                UPDATE file_id = file_id;
+            `;
+            const values = [file_id, source_id, md5, mimetype, size, name, path];
+            // 直接接收 execute 返回的内容
+            const result = await connection.execute(sql, values);
+            return resolve(result);
+        } catch (err) {
+            return resolve(false);
+        }
+    });
 }
 
 export async function 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 {
-      const sql = `
-          INSERT INTO book_link_file (file_id, book_id, author_id)
-          VALUES (?, ?, ?);
-        `;
-
-      const values = [file_id, book_id, author_id];
-      // 直接接收 execute 返回的内容
-      connection.execute(sql, values, (err, row) => {
-        if (err) {
-          console.log(606060, err);
-          return resolve(false);
+                                                 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 {
+            const sql = `
+                INSERT INTO book_link_file (file_id, book_id, author_id)
+                VALUES (?, ?, ?);
+            `;
+            
+            const values = [file_id, book_id, author_id];
+            // 直接接收 execute 返回的内容
+            connection.execute(sql, values, (err, row) => {
+                if (err) {
+                    console.log(606060, err);
+                    return resolve(false);
+                }
+                return resolve(row);
+            });
+        } catch (err) {
+            return resolve(false);
         }
-        return resolve(row);
-      });
-    } catch (err) {
-      return resolve(false);
-    }
-  });
+    });
 }
 
 // 查询图片信息
 export function getFileBymd5(md5Str) {
-  return new Promise((resolve, reject) => {
-    connection.query(
-      `SELECT files.*, book_link_file.book_id AS book_id
-       FROM files
-       JOIN book_link_file ON files.file_id = book_link_file.file_id
-       WHERE files.file_id = ?`,
-      [md5Str],
-      (err, rows) => {
-        if (err) {
-          resolve(false); // 如果出现错误,返回 false
-        } else {
-          resolve(rows.length > 0 ? rows[0] : false); // 如果存在记录,返回第一条记录,否则返回 false
-        }
-      }
-    );
-  });
+    return new Promise((resolve, reject) => {
+        connection.query(
+            `SELECT files.*, book_link_file.book_id AS book_id
+             FROM files
+                      JOIN book_link_file ON files.file_id = book_link_file.file_id
+             WHERE files.file_id = ?`,
+            [md5Str],
+            (err, rows) => {
+                if (err) {
+                    resolve(false); // 如果出现错误,返回 false
+                } else {
+                    resolve(rows.length > 0 ? rows[0] : false); // 如果存在记录,返回第一条记录,否则返回 false
+                }
+            }
+        );
+    });
 }
 
 // 查询图片信息
 export function searchFileByPath(imgPath, file_md5) {
-  return new Promise((resolve, reject) => {
-    connection.query(
-      `SELECT * FROM files WHERE path like ? ${
-        file_md5 ? "and path like ?" : ""
-      };`,
-      [`%${imgPath}%`, `%${file_md5}%`],
-      (err, rows) => {
-        if (err) {
-          resolve(false); // 如果存在记录,则返回 true,否则返回 false
-        } else {
-          resolve(rows.length > 0 ? rows[0] : false); // 如果存在记录,则返回 true,否则返回 false
-        }
-      }
-    );
-  });
+    return new Promise((resolve, reject) => {
+        connection.query(
+            `SELECT *
+             FROM files
+             WHERE path like ? ${file_md5 ? "and path like ?" : ""};`,
+            [`%${imgPath}%`, `%${file_md5}%`],
+            (err, rows) => {
+                if (err) {
+                    resolve(false); // 如果存在记录,则返回 true,否则返回 false
+                } else {
+                    resolve(rows.length > 0 ? rows[0] : false); // 如果存在记录,则返回 true,否则返回 false
+                }
+            }
+        );
+    });
+}
+
+// 查询图片信息
+export function searchFileByName(fileName, fileMd5) {
+    return new Promise((resolve, reject) => {
+        const query = `
+            SELECT *
+            FROM files
+                     JOIN book_link_file ON files.file_id = book_link_file.file_id
+                AND book_link_file.book_id = ?
+            WHERE name LIKE ? ${fileMd5 ? "OR path LIKE ?" : ""};
+        `;
+        
+        const queryParams = fileMd5
+            ? [fileMd5, `%${fileName}%`, `%${fileMd5}%`]
+            : [fileMd5, `%${fileName}%`];
+        
+        connection.query(query, queryParams, (err, rows) => {
+            if (err) {
+                return reject(err);
+            }
+            
+            resolve(rows.length > 0 ? rows[0] : false);
+        });
+    });
 }
+

+ 2 - 1
epub_node/db/index.js

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

+ 104 - 1
epub_node/db/update.sql

@@ -1 +1,104 @@
-ALTER TABLE epub_manage.files ADD source_id varchar(100) NULL;
+create table author
+(
+    id int auto_increment primary key,
+    name        varchar(255) not null,
+    author_id   varchar(100) not null,
+    create_time timestamp default CURRENT_TIMESTAMP null,
+    update_time timestamp default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP,
+    constraint author_id_unique unique (author_id)
+);
+
+create table book
+(
+    id int auto_increment primary key,
+    book_name     varchar(255) not null,
+    book_id       varchar(100) not null,
+    book_md5      varchar(32)  not null,
+    language      varchar(50) null comment '语言',
+    date          date null comment '创建时间',
+    creatorFileAs varchar(255) null comment '电子书创建人',
+    UUID          varchar(36) null comment '电子书唯一编号',
+    ISBN          varchar(20) null comment '电子书出版编号',
+    author_id     varchar(100) not null comment '作者id',
+    category_id   varchar(255) null comment '书籍类别编号',
+    Introduction  text null comment '简介',
+    create_time   timestamp default CURRENT_TIMESTAMP null,
+    update_time   timestamp default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP,
+    constraint book_id_unique unique (book_id)
+) comment '书籍信息';
+
+create table category
+(
+    id int auto_increment primary key,
+    name        varchar(255) not null,
+    create_time timestamp default CURRENT_TIMESTAMP null,
+    update_time timestamp default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP
+);
+
+create table chapter
+(
+    id int auto_increment primary key,
+    name        varchar(255) not null,
+    book_id     varchar(100) not null,
+    author_id   varchar(100) not null,
+    content     longtext null,
+    level       int null,
+    order_index int null,
+    order_id    varchar(255) null,
+    old_path    varchar(255) null,
+    path        varchar(255) null,
+    create_time timestamp default CURRENT_TIMESTAMP null,
+    update_time timestamp default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP,
+    constraint fk_chapter_author foreign key (author_id) references author (author_id) on delete cascade,
+    constraint fk_chapter_book foreign key (book_id) references book (book_id) on delete cascade
+);
+
+create table files
+(
+    id int auto_increment primary key,
+    file_id     varchar(100) not null,
+    md5         varchar(32)  not null,
+    mimetype    varchar(255) not null,
+    size        int          not null,
+    name        varchar(255) null,
+    path        varchar(255) null,
+    create_time timestamp default CURRENT_TIMESTAMP null,
+    update_time timestamp default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP,
+    constraint file_id_unique unique (file_id)
+);
+
+create table book_link_file
+(
+    id int auto_increment primary key,
+    file_id     varchar(100) not null,
+    book_id     varchar(100) not null,
+    author_id   varchar(100) not null,
+    create_time timestamp default CURRENT_TIMESTAMP null,
+    update_time timestamp default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP,
+    constraint fk_book_file foreign key (file_id) references files (file_id) on delete cascade,
+    constraint fk_link_author foreign key (author_id) references author (author_id) on delete cascade,
+    constraint fk_link_book foreign key (book_id) references book (book_id) on delete cascade
+);
+
+create table style
+(
+    id int auto_increment primary key,
+    name        varchar(255) not null,
+    style_id    varchar(100) not null,
+    create_time timestamp default CURRENT_TIMESTAMP null,
+    update_time timestamp default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP,
+    constraint style_id_unique unique (style_id)
+);
+
+create table style_link_book
+(
+    id int auto_increment primary key,
+    style_id    varchar(100) not null,
+    book_id     varchar(100) not null,
+    create_time timestamp default CURRENT_TIMESTAMP null,
+    update_time timestamp default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP,
+    constraint style_book_unique unique (style_id, book_id),
+    constraint fk_book foreign key (book_id) references book (book_id) on delete cascade,
+    constraint fk_style foreign key (style_id) references style (style_id) on delete cascade
+);
+

+ 7 - 7
epub_node/environment/index.js

@@ -1,12 +1,12 @@
 function dbInfo() {
   // 根据需要更新db的数据配置
-  // return {
-  //   host: "localhost",
-  //   port: 3306,
-  //   user: "root",
-  //   password: "12345678",
-  //   database: "epub_manage",
-  // };
+  return {
+    host: "localhost",
+    port: 3306,
+    user: "root",
+    password: "12345678",
+    database: "epub_manage",
+  };
   return {
     host: "192.168.2.101",
     port: 6806,

+ 14 - 10
epub_node/router/epub/index.js

@@ -17,6 +17,7 @@ import { saveImgs, calculateMD5 } from "./image.js";
 import { htmlParser, saveMateInfo } from "./txt.js";
 import { saveAllCSS } from "./style.js";
 import { saveAllFount } from "./font.js";
+import { saveToc } from "./toc.js";
 
 const router = express.Router();
 
@@ -60,17 +61,14 @@ router.get("/html/:fileId", async function (req, res) {
 router.get("/img/:fileId", async function (req, res) {
   const fileId = req.params.fileId; // 获取 fileId 参数
   logger.info(`Found ${fileId}`);
-  console.log(6262626, fileId);
 
   const fileRow = await getFileBymd5(fileId);
-  console.log(6565, fileRow);
 
   if (!fileRow) {
     return res.status(404).send("文件查询失败");
   }
   const uploadPath = "./base_files/" + fileRow.book_id + "/image/" + fileId;
   const filePath = path.resolve(uploadPath);
-  console.log(727272, filePath, fs.existsSync(filePath));
 
   // 检查文件是否存在
   if (!fs.existsSync(filePath)) {
@@ -149,12 +147,8 @@ router.put("/", async function (req, res) {
   } else {
     epub = await EPub.createAsync(epubData, null, "");
   }
-
-  res.send("About types");
-  console.log(137, typeof epub.metadata.creator, epub.metadata.creator);
-  // 作者
-  // const author_id = await author_insert()
-
+  
+  // 生成作者的数据
   let authorInfo = await get_author_info(epub.metadata.creator);
   let author_id = authorInfo.author_id;
   if (!authorInfo) {
@@ -166,14 +160,24 @@ router.put("/", async function (req, res) {
     2、替换文件中的图片内容
     3、存储html数据
     4、存储css数据
+    5、存储章节数据
    */
   await saveMateInfo(epub, uploadPath, file_md5, author_id)
+  logger.info('书籍的基础数据处理完毕')
   await saveImgs(epub, uploadPath, file_md5, author_id);
+  logger.info('书籍的图片数据处理完毕')
   await saveAllFount(epub, uploadPath, file_md5, author_id);
+  logger.info('书籍的字体数据处理完毕')
   await saveAllCSS(epub, uploadPath, file_md5, author_id);
+  logger.info('书籍的css数据处理完毕')
   // 存储html数据
   await htmlParser(epub, zipEpubExtract, file_md5, author_id);
-  console.log('书籍处理完毕')
+  logger.info('书籍的章节数据处理完毕')
+  // 章节数据
+  await saveToc(epub, zipEpubExtract, file_md5, author_id);
+  logger.info('书籍的目录处理完毕')
+  logger.info('书籍处理完毕')
+  res.send("书籍处理完毕");
 });
 
 export default router;

+ 33 - 0
epub_node/router/epub/toc.js

@@ -0,0 +1,33 @@
+import logger from "#logger";
+import {chapter_insert, searchChapterInfoForPath} from "#db";
+import {dirExists} from "#utils";
+import fs from "node:fs";
+import {calculateMD5} from "./image.js";
+
+// ./base_files/5ae2d9158081faab184484ed1783e176
+export async function saveToc(epub, uploadPath, book_id, author_id) {
+    await Promise.all(epub.toc.map(async (elm) => {
+        const match = `${elm.href}`.match(/\/(.*\.html).*/)
+        let chapterInfo = {
+            file_id: ''
+        }
+        let path = ''
+        if (match) {
+            path = match[1];
+            chapterInfo = await searchChapterInfoForPath(path, book_id)
+        }
+        
+        const params = {
+            name: elm.title,
+            book_id: book_id,
+            author_id: author_id,
+            content: JSON.stringify(elm),
+            level: elm.level,
+            order_index: elm.order,
+            order_id: chapterInfo.file_id,
+            old_path: elm.href,
+            path: `./base_files/${book_id}/Text/${chapterInfo.file_id}.html`,
+        }
+        return await chapter_insert(params)
+    }))
+}

+ 134 - 130
epub_node/router/epub/txt.js

@@ -1,147 +1,151 @@
 import fs from "node:fs";
 import path from "node:path";
-import { dirExists, isFileSync, isDir, waittime } from "#utils";
+import {dirExists, isFileSync, isDir, waittime} from "#utils";
 import {
-  getFileBymd5,
-  searchFileByPath,
-  files_insert_link_epub,
-  files_insert,
-  book_mate_insert,
+    getFileBymd5,
+    searchFileByPath,
+    searchFileByName,
+    files_insert_link_epub,
+    files_insert,
+    book_mate_insert,
 } from "#db";
-import { calculateMD5 } from "./image.js";
+import {calculateMD5} from "./image.js";
 
 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.includes("Images") &&
-      imageExtensions.some((ext) => rowtext.includes(ext))
-    ) {
-      const match = rowtext.match(/.*(..\/Images\/(.*\.(jpg|png|jpeg|svg))).*/);
-      if (match) {
-        const [, imgPath, imageSrc] = match;
-        const imgRow = await searchFileByPath(imageSrc);
-        if (imgRow) {
-          return (
-            rowtext.replace(imgPath, `/api/v1/epub/img/${imgRow.file_id}`) +
-            "\n"
-          );
+    const rows = elmData.toString().split(/\n/);
+    const promises = rows.map(async (rowtext) => {
+        if (
+            rowtext.includes("<img ") &&
+            imageExtensions.some((ext) => rowtext.includes(ext))
+        ) {
+            // const match = rowtext.match(/.*(..\/Images\/(.*\.(jpg|png|jpeg|svg))).*/);
+            const match = rowtext.match(/src=("|')(.*\/(.*\.[a-zA-Z]+))("|')/)
+            if (match) {
+                const [, , imgPath, imageSrc] = match;
+                const imgRow = await searchFileByPath(imageSrc);
+                if (imgRow) {
+                    return (
+                        rowtext.replace(imgPath, `/api/v1/epub/img/${imgRow.file_id}`) +
+                        "\n"
+                    );
+                }
+            }
+        } else if (rowtext.includes(".css")) {
+            const match = rowtext.match(/.*="(.*\/?(.*\.css))/);
+            const [elmPath, elmName] = `${rowtext}`.match(/.*\/(.*\.css)/);
+            if (match) {
+                const [, cssPath, cssSrc] = match;
+                // const imgRow = await searchFileByPath(elmName, file_md5);
+                const imgNameRow =  await searchFileByName(elmName, file_md5);
+                if (imgNameRow) {
+                    return (
+                        rowtext.replace(cssPath, `/api/v1/epub/css/${imgNameRow.file_id}`) +
+                        "\n"
+                    );
+                }
+            }
+        } else if (rowtext.includes(".ttf")) {
+            // 使用正则表达式匹配路径和文件名
+            const match = rowtext.match(/.*\((.*\/?(.*ttf))\)./);
+            if (match) {
+                const [, cssPath, cssSrc] = match;
+                try {
+                    // 搜索数据库中是否存在该字体文件
+                    const imgRow = await searchFileByPath(cssSrc, file_md5);
+                    if (imgRow) {
+                        // 如果找到,替换路径为 API 端点
+                        console.log(57, rowtext);
+                        console.log(58, cssPath, cssSrc);
+                        console.log(59, `/api/v1/epub/css/${imgRow.file_id}`);
+                        
+                        return (
+                            rowtext.replace(cssPath, `/api/v1/epub/css/${imgRow.file_id}`) +
+                            "\n"
+                        );
+                    } else {
+                        console.warn(`Font file not found for path: ${cssSrc}`);
+                    }
+                } catch (error) {
+                    console.error("Error searching for font file:", error);
+                }
+            }
         }
-      }
-    } else if (rowtext.includes(".css")) {
-      const match = rowtext.match(/.*="(.*\/?(.*\.css))/);
-      if (match) {
-        const [, cssPath, cssSrc] = match;
-        const imgRow = await searchFileByPath(cssSrc, file_md5);
-        if (imgRow) {
-          return (
-            rowtext.replace(cssPath, `/api/v1/epub/css/${imgRow.file_id}`) +
-            "\n"
-          );
-        }
-      }
-    } else if (rowtext.includes(".ttf")) {
-      // 使用正则表达式匹配路径和文件名
-      const match = rowtext.match(/.*\((.*\/?(.*ttf))\)./);
-      if (match) {
-        const [, cssPath, cssSrc] = match;
-        try {
-          // 搜索数据库中是否存在该字体文件
-          const imgRow = await searchFileByPath(cssSrc, file_md5);
-          if (imgRow) {
-            // 如果找到,替换路径为 API 端点
-            console.log(57, rowtext);
-            console.log(58, cssPath, cssSrc);
-            console.log(59, `/api/v1/epub/css/${imgRow.file_id}`);
-
-            return (
-              rowtext.replace(cssPath, `/api/v1/epub/css/${imgRow.file_id}`) +
-              "\n"
-            );
-          } else {
-            console.warn(`Font file not found for path: ${cssSrc}`);
-          }
-        } catch (error) {
-          console.error("Error searching for font file:", error);
-        }
-      }
-    }
-
-    return rowtext + "\n";
-  });
-
-  const results = await Promise.all(promises);
-  return results.join("");
+        
+        return rowtext + "\n";
+    });
+    
+    const results = await Promise.all(promises);
+    return results.join("");
 }
 
 export async function htmlParser(epub, zipEpubExtract, file_md5, author_id) {
-  const needSetImage = epub.zip.names.filter(
-    (elm) => elm.endsWith(".html") || elm.endsWith(".css")
-  );
-
-  const needSetFont = epub.zip.names.filter((elm) => elm.endsWith(".ttf"));
-  const basePath = path.join("./base_files", file_md5, "Text");
-  const styleBasePath = path.join("./base_files", file_md5, "style");
-  dirExists(basePath);
-  dirExists(styleBasePath);
-
-  await Promise.all(
-    needSetImage.map(async (elm) => {
-      const filePath = path.join(zipEpubExtract, elm);
-      const elmData = fs.readFileSync(filePath);
-      const htmlStr = await processFiles(elmData, file_md5);
-
-      if (htmlStr) {
-        fs.writeFileSync(filePath, htmlStr);
-
-        const htmlMd5 = await calculateMD5(filePath);
-        const isCss = elm.endsWith(".css");
-        const newFilePath = path.join(
-          isCss ? styleBasePath : basePath,
-          `${htmlMd5}.${isCss ? "css" : "html"}`
-        );
-
-        const params = {
-          file_id: htmlMd5,
-          md5: htmlMd5,
-          mimetype: isCss ? "text/css" : "text/html",
-          size: Buffer.byteLength(htmlStr),
-          name: `${htmlMd5}.${isCss ? "css" : "html"}`,
-          path: newFilePath,
-          source_id: elm,
-        };
-        await files_insert(params);
-        await Promise.all([
-          files_insert_link_epub({
-            file_id: htmlMd5,
-            book_id: file_md5,
-            author_id,
-          }),
-          fs.promises.writeFile(newFilePath, htmlStr),
-        ]);
-      }
-    })
-  );
+    const needSetImage = epub.zip.names.filter(
+        (elm) => elm.endsWith(".html") || elm.endsWith(".css")
+    );
+    
+    const needSetFont = epub.zip.names.filter((elm) => elm.endsWith(".ttf"));
+    const basePath = path.join("./base_files", file_md5, "Text");
+    const styleBasePath = path.join("./base_files", file_md5, "style");
+    dirExists(basePath);
+    dirExists(styleBasePath);
+    
+    await Promise.all(
+        needSetImage.map(async (elm) => {
+            const filePath = path.join(zipEpubExtract, elm);
+            const elmData = fs.readFileSync(filePath);
+            const htmlStr = await processFiles(elmData, file_md5);
+            
+            if (htmlStr) {
+                fs.writeFileSync(filePath, htmlStr);
+                
+                const htmlMd5 = await calculateMD5(filePath);
+                const isCss = elm.endsWith(".css");
+                const newFilePath = path.join(
+                    isCss ? styleBasePath : basePath,
+                    `${htmlMd5}.${isCss ? "css" : "html"}`
+                );
+                
+                const params = {
+                    file_id: htmlMd5,
+                    md5: htmlMd5,
+                    mimetype: isCss ? "text/css" : "text/html",
+                    size: Buffer.byteLength(htmlStr),
+                    name: `${htmlMd5}.${isCss ? "css" : "html"}`,
+                    path: newFilePath,
+                    source_id: elm,
+                };
+                await files_insert(params);
+                await Promise.all([
+                    files_insert_link_epub({
+                        file_id: htmlMd5,
+                        book_id: file_md5,
+                        author_id,
+                    }),
+                    fs.promises.writeFile(newFilePath, htmlStr),
+                ]);
+            }
+        })
+    );
 }
 
 // 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);
+    // 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);
 }