|
@@ -7,7 +7,7 @@ import express from "express";
|
|
import { EPub } from "epub2";
|
|
import { EPub } from "epub2";
|
|
import { dirExists, isFileSync, isDir, waittime } from "#utils";
|
|
import { dirExists, isFileSync, isDir, waittime } from "#utils";
|
|
|
|
|
|
-import { saveImgs } from "./image.js";
|
|
|
|
|
|
+import { saveImgs, calculateMD5 } from "./image.js";
|
|
import { htmlParser } from "./txt.js";
|
|
import { htmlParser } from "./txt.js";
|
|
import { saveAllCSS } from "./style.js";
|
|
import { saveAllCSS } from "./style.js";
|
|
|
|
|
|
@@ -32,7 +32,8 @@ router.get("/html", function (req, res) {
|
|
// 构建文件的绝对路径
|
|
// 构建文件的绝对路径
|
|
const filePath = path.join(
|
|
const filePath = path.join(
|
|
process.cwd(),
|
|
process.cwd(),
|
|
- "./base_files/2a0b8153f3ede4bd43abb3b0e38ee857/epub-extract/OEBPS/Text/:::::::::::::::::::::*:*::**::*:.html"
|
|
|
|
|
|
+ // "./base_files/2a0b8153f3ede4bd43abb3b0e38ee857/epub-extract/OEBPS/Text/:::::::::::::::::::::*:*::**::*:.html"
|
|
|
|
+ "./base_files/5ae2d9158081faab184484ed1783e176/epub-extract/OEBPS/text00040.html"
|
|
);
|
|
);
|
|
|
|
|
|
// 发送文件
|
|
// 发送文件
|
|
@@ -65,6 +66,28 @@ router.get("/img/:fileId", async function (req, res) {
|
|
res.sendFile(filePath);
|
|
res.sendFile(filePath);
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+
|
|
|
|
+router.get("/css/:fileId", async function (req, res) {
|
|
|
|
+ const fileId = req.params.fileId; // 获取 fileId 参数
|
|
|
|
+ logger.info(`Found ${fileId}`);
|
|
|
|
+ const fileRow = await getFileBymd5(fileId);
|
|
|
|
+
|
|
|
|
+ if (!fileRow) {
|
|
|
|
+ return res.status(404).send("文件查询失败");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const filePath = path.resolve(fileRow.path);
|
|
|
|
+ console.log(79, filePath)
|
|
|
|
+ // 检查文件是否存在
|
|
|
|
+ if (!fs.existsSync(filePath)) {
|
|
|
|
+ return res.status(404).send("服务器中不存在该文件");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 返回文件
|
|
|
|
+ res.setHeader("Content-Type", fileRow.mimetype);
|
|
|
|
+ res.sendFile(filePath);
|
|
|
|
+});
|
|
|
|
+
|
|
// define the about route
|
|
// define the about route
|
|
router.put("/", async function (req, res) {
|
|
router.put("/", async function (req, res) {
|
|
let sampleFile;
|
|
let sampleFile;
|
|
@@ -80,7 +103,7 @@ router.put("/", async function (req, res) {
|
|
|
|
|
|
sampleFile = req.files.file;
|
|
sampleFile = req.files.file;
|
|
|
|
|
|
- const file_md5 = sampleFile.md5;
|
|
|
|
|
|
+ let file_md5 = sampleFile.md5;
|
|
uploadPath = `./base_files/${file_md5}/`;
|
|
uploadPath = `./base_files/${file_md5}/`;
|
|
epubFilePath = uploadPath + sampleFile.md5 + '.epub';
|
|
epubFilePath = uploadPath + sampleFile.md5 + '.epub';
|
|
zipEpubExtract = uploadPath + "epub-extract/";
|
|
zipEpubExtract = uploadPath + "epub-extract/";
|
|
@@ -99,6 +122,7 @@ router.put("/", async function (req, res) {
|
|
epubData = sampleFile.data;
|
|
epubData = sampleFile.data;
|
|
} else {
|
|
} else {
|
|
epubData = fs.readFileSync(epubFilePath);
|
|
epubData = fs.readFileSync(epubFilePath);
|
|
|
|
+ file_md5 = await calculateMD5(epubFilePath)
|
|
}
|
|
}
|
|
|
|
|
|
/* 是否需要解压文件 */
|
|
/* 是否需要解压文件 */
|
|
@@ -131,11 +155,13 @@ router.put("/", async function (req, res) {
|
|
3、存储html数据
|
|
3、存储html数据
|
|
4、存储css数据
|
|
4、存储css数据
|
|
*/
|
|
*/
|
|
- // await saveImgs(epub, uploadPath);
|
|
|
|
|
|
+ await saveImgs(epub, uploadPath);
|
|
await saveAllCSS(epub, uploadPath)
|
|
await saveAllCSS(epub, uploadPath)
|
|
|
|
|
|
// 存储html数据
|
|
// 存储html数据
|
|
- // await htmlParser(epub, zipEpubExtract);
|
|
|
|
|
|
+ const test = await htmlParser(epub, zipEpubExtract, file_md5);
|
|
|
|
+
|
|
|
|
+
|
|
// console.log("\nSPINE:\n");
|
|
// console.log("\nSPINE:\n");
|
|
// // console.log(epub.flow);
|
|
// // console.log(epub.flow);
|
|
// epub.flow.forEach((elm) => {
|
|
// epub.flow.forEach((elm) => {
|