|
@@ -15,18 +15,11 @@ 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|svg))).*/);
|
|
|
- if (rowtext.indexOf(".svg") > -1) {
|
|
|
- console.log(2323, match, rowtext);
|
|
|
- }
|
|
|
-
|
|
|
if (match) {
|
|
|
const [, imgPath, imageSrc] = match;
|
|
|
const imgRow = await searchFileByPath(imageSrc);
|
|
@@ -49,7 +42,33 @@ async function processFiles(elmData, file_md5) {
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
+ } 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";
|
|
|
});
|
|
|
|
|
@@ -62,8 +81,11 @@ export async function htmlParser(epub, zipEpubExtract, file_md5, author_id) {
|
|
|
(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) => {
|
|
@@ -75,14 +97,18 @@ export async function htmlParser(epub, zipEpubExtract, file_md5, author_id) {
|
|
|
fs.writeFileSync(filePath, htmlStr);
|
|
|
|
|
|
const htmlMd5 = await calculateMD5(filePath);
|
|
|
- const newFilePath = path.join(basePath, `${htmlMd5}.html`);
|
|
|
+ const isCss = elm.endsWith(".css");
|
|
|
+ const newFilePath = path.join(
|
|
|
+ isCss ? styleBasePath : basePath,
|
|
|
+ `${htmlMd5}.${isCss ? "css" : "html"}`
|
|
|
+ );
|
|
|
|
|
|
const params = {
|
|
|
file_id: htmlMd5,
|
|
|
md5: htmlMd5,
|
|
|
- mimetype: "text/html",
|
|
|
+ mimetype: isCss ? "text/css" : "text/html",
|
|
|
size: Buffer.byteLength(htmlStr),
|
|
|
- name: `${htmlMd5}.html`,
|
|
|
+ name: `${htmlMd5}.${isCss ? "css" : "html"}`,
|
|
|
path: newFilePath,
|
|
|
source_id: elm,
|
|
|
};
|