123456789101112131415161718192021222324252627282930313233 |
- 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)
- }))
- }
|