|
@@ -27,40 +27,50 @@ router.use(function timeLog(req, res, next) {
|
|
router.get("/", async function (req, res) {
|
|
router.get("/", async function (req, res) {
|
|
res.send("epub types");
|
|
res.send("epub types");
|
|
});
|
|
});
|
|
|
|
+
|
|
// define the about route
|
|
// define the about route
|
|
router.get("/about", function (req, res) {
|
|
router.get("/about", function (req, res) {
|
|
res.send("About types");
|
|
res.send("About types");
|
|
});
|
|
});
|
|
-router.get("/html", function (req, res) {
|
|
|
|
- //
|
|
|
|
- // res.sendFile('base_files/2a0b8153f3ede4bd43abb3b0e38ee857/epub-extract/OEBPS/Text/:::::::::::::::::::::*:*::**::*:.html')
|
|
|
|
- // res.send("About types");
|
|
|
|
- // 构建文件的绝对路径
|
|
|
|
- const filePath = path.join(
|
|
|
|
- process.cwd(),
|
|
|
|
- // "./base_files/2a0b8153f3ede4bd43abb3b0e38ee857/epub-extract/OEBPS/Text/:::::::::::::::::::::*:*::**::*:.html"
|
|
|
|
- "./base_files/5ae2d9158081faab184484ed1783e176/epub-extract/OEBPS/text00040.html"
|
|
|
|
- );
|
|
|
|
-
|
|
|
|
- // 发送文件
|
|
|
|
- res.sendFile(filePath, function (err) {
|
|
|
|
- if (err) {
|
|
|
|
- console.error("Error sending file:", err);
|
|
|
|
- res.status(500).send("File not found or other error occurred.");
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
|
|
+
|
|
|
|
+router.get("/html/: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 uploadPath =
|
|
|
|
+ "./base_files/" + fileRow.book_id + "/Text/" + fileId + ".html";
|
|
|
|
+ console.log(46, fileRow);
|
|
|
|
+
|
|
|
|
+ const filePath = path.resolve(uploadPath);
|
|
|
|
+ // 检查文件是否存在
|
|
|
|
+ if (!fs.existsSync(filePath)) {
|
|
|
|
+ return res.status(404).send("服务器中不存在该文件");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 返回文件
|
|
|
|
+ res.setHeader("Content-Type", fileRow.mimetype);
|
|
|
|
+ res.sendFile(filePath);
|
|
});
|
|
});
|
|
|
|
|
|
router.get("/img/:fileId", async function (req, res) {
|
|
router.get("/img/:fileId", async function (req, res) {
|
|
const fileId = req.params.fileId; // 获取 fileId 参数
|
|
const fileId = req.params.fileId; // 获取 fileId 参数
|
|
logger.info(`Found ${fileId}`);
|
|
logger.info(`Found ${fileId}`);
|
|
|
|
+ console.log(6262626, fileId);
|
|
|
|
+
|
|
const fileRow = await getFileBymd5(fileId);
|
|
const fileRow = await getFileBymd5(fileId);
|
|
|
|
+ console.log(6565, fileRow);
|
|
|
|
|
|
if (!fileRow) {
|
|
if (!fileRow) {
|
|
return res.status(404).send("文件查询失败");
|
|
return res.status(404).send("文件查询失败");
|
|
}
|
|
}
|
|
const uploadPath = "./base_files/" + fileRow.book_id + "/image/" + fileId;
|
|
const uploadPath = "./base_files/" + fileRow.book_id + "/image/" + fileId;
|
|
const filePath = path.resolve(uploadPath);
|
|
const filePath = path.resolve(uploadPath);
|
|
|
|
+ console.log(727272, filePath, fs.existsSync(filePath));
|
|
|
|
+
|
|
// 检查文件是否存在
|
|
// 检查文件是否存在
|
|
if (!fs.existsSync(filePath)) {
|
|
if (!fs.existsSync(filePath)) {
|
|
return res.status(404).send("服务器中不存在该文件");
|
|
return res.status(404).send("服务器中不存在该文件");
|
|
@@ -79,8 +89,10 @@ router.get("/css/:fileId", async function (req, res) {
|
|
if (!fileRow) {
|
|
if (!fileRow) {
|
|
return res.status(404).send("文件查询失败");
|
|
return res.status(404).send("文件查询失败");
|
|
}
|
|
}
|
|
|
|
+ const uploadPath =
|
|
|
|
+ "./base_files/" + fileRow.book_id + "/style/" + fileId + ".css";
|
|
|
|
|
|
- const filePath = path.resolve(fileRow.path);
|
|
|
|
|
|
+ const filePath = path.resolve(uploadPath);
|
|
// 检查文件是否存在
|
|
// 检查文件是否存在
|
|
if (!fs.existsSync(filePath)) {
|
|
if (!fs.existsSync(filePath)) {
|
|
return res.status(404).send("服务器中不存在该文件");
|
|
return res.status(404).send("服务器中不存在该文件");
|
|
@@ -156,9 +168,8 @@ router.put("/", async function (req, res) {
|
|
*/
|
|
*/
|
|
await saveImgs(epub, uploadPath, file_md5, author_id);
|
|
await saveImgs(epub, uploadPath, file_md5, author_id);
|
|
await saveAllCSS(epub, uploadPath, file_md5, author_id);
|
|
await saveAllCSS(epub, uploadPath, file_md5, author_id);
|
|
-
|
|
|
|
// 存储html数据
|
|
// 存储html数据
|
|
- const test = await htmlParser(epub, zipEpubExtract, file_md5);
|
|
|
|
|
|
+ await htmlParser(epub, zipEpubExtract, file_md5, author_id);
|
|
|
|
|
|
// console.log("\nSPINE:\n");
|
|
// console.log("\nSPINE:\n");
|
|
// // console.log(epub.flow);
|
|
// // console.log(epub.flow);
|