1234567891011121314151617181920212223242526272829303132333435363738 |
- 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) => {
- try {
- const match = `${elm.href}`.match(/\/(.*\.html).*/)
- let chapterInfo = {
- file_id: ''
- }
- let path = ''
- if (match) {
- path = match[1];
- chapterInfo = await searchChapterInfoForPath(path, book_id)
- }
- logger.info(elm)
- 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`,
- }
- logger.info(params)
- return await chapter_insert(params)
- } catch (e) {
- logger.error(e)
- }
- }))
- }
|