1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- import express from "express";
- import path from "path";
- import fs from "node:fs";
- import { EPub } from "epub2";
- const router = express.Router();
- router.use(function timeLog(req, res, next) {
- console.log("Time: ", Date.now());
- next();
- });
- // define the about route
- router.put("/", function (req, res) {
- let sampleFile;
- if (!req.files || Object.keys(req.files).length === 0) {
- return res.status(400).send("No files were uploaded.");
- }
- sampleFile = req.files.file;
- EPub.createAsync(sampleFile.data, "", null)
- .then(async function (epub) {
- console.log(epub.filename.length);
- console.log("METADATA:\n");
- // console.log(epub['Symbol(rawData)']);
- console.log(epub);
- // console.log(23, epub.filename);
- // console.log("METADATA:\n");
- // console.log(epub.metadata);
- // console.log("\nSPINE:\n");
- // console.log(epub.flow);
- // console.log("\nTOC:\n");
- // console.log(epub.toc);
- // get first chapter
- // await epub
- // .getChapterAsync(epub.spine.contents[1].id)
- // .then(function (data) {
- // console.log(383838, data);
- // });
- // console.log("\nmanifest:\n");
- // console.log(epub.manifest);
- // console.log("\nlistImage:\n");
- // let imgs = epub.listImage();
- // imgs.forEach((elm) => {
- // if (elm.id.indexOf("cover") > -1) {
- // console.log(505050, elm);
- // }
- // });
- // await epub
- // // .getImageAsync(imgs[imgs.length - 2].id)
- // .getImageAsync('cover-image')
- // .then(([bufferData, mimeType]) => {
- // console.log(`\ngetImage: cover\n`);
- // console.log(52, bufferData);
- // console.log(52, mimeType);
- // // 返回文件
- // // res.setHeader("Content-Type", mimeType);
- // // res.sendFile(data);
- // // 设置响应头,指定内容类型为 PNG 图片
- // res.writeHead(200, {
- // "Content-Type": mimeType,
- // "Content-Length": bufferData.length,
- // });
- // // 将 Buffer 数据发送到客户端
- // res.end(bufferData);
- // });
- })
- .catch(function (err) {
- console.log("ERROR\n-----");
- throw err;
- });
- res.send("About files");
- });
- export default router;
|