Files
reader/lib/epub-split.ts
T
virtus 878018ca11
Build and Push Reader Image / docker (push) Successful in 1m32s
refactor: Streamline EPUB handling with new split modes and improved error management
- Removed legacy AI Tool references and unnecessary fields from the README and various components.
- Introduced new EPUB split modes (toc, regex, tag) to enhance flexibility in chapter extraction.
- Updated import and chapter management components to utilize the new EPUB split functionality.
- Improved error handling in the login API route for better user feedback.
- Cleaned up unused files and optimized the overall code structure for maintainability.
2026-05-19 00:15:19 +07:00

32 lines
1.0 KiB
TypeScript

export type EpubSplitMode = "toc" | "regex" | "tag"
export const EPUB_HTML_TAG_PRESETS = [
{ id: "a", name: "Thẻ <a> (anchor / mục lục liên kết)", tag: "a" },
{ id: "h2", name: "Thẻ <h2>", tag: "h2" },
{ id: "h1", name: "Thẻ <h1>", tag: "h1" },
{ id: "h3", name: "Thẻ <h3>", tag: "h3" },
{ id: "p", name: "Thẻ <p>", tag: "p" },
] as const
export const DEFAULT_EPUB_CHAPTER_TAG = "a"
export function splitModeLabel(mode: string | undefined): string {
if (mode === "regex") return "Regex"
if (mode === "tag") return "Thẻ HTML"
return "TOC"
}
export function appendEpubSplitFormFields(
form: FormData,
splitMode: EpubSplitMode,
options?: { chapterRegex?: string; chapterTag?: string },
) {
form.append("splitMode", splitMode)
if (splitMode === "regex" && options?.chapterRegex) {
form.append("chapterRegex", options.chapterRegex)
}
if (splitMode === "tag") {
form.append("chapterTag", (options?.chapterTag || DEFAULT_EPUB_CHAPTER_TAG).trim() || DEFAULT_EPUB_CHAPTER_TAG)
}
}