Remove ExportBook component and integrate new export workflows
- Deleted `ExportBook` component and its usage in `BookCard.tsx`. - Integrated improved book export workflows in `BookSettingOption` for better user experience. - Updated database models and repositories to support export options with chapter/version selection. - Added localization support for export-related messages and tooltips. - Upgraded dependencies to include libraries required for export formats (e.g., DOCX, PDF, EPUB). - Bumped app version to 0.4.1.
This commit is contained in:
@@ -3,9 +3,12 @@ import { getUserEncryptionKey } from "../keyManager.js";
|
||||
import Book, { CompleteBookData } from "./Book.js";
|
||||
import ChapterRepo, {
|
||||
ActChapterQuery,
|
||||
ChapterExportInfoResult,
|
||||
ChapterQueryResult,
|
||||
ChapterSelectionParam,
|
||||
ChapterStoryQueryResult,
|
||||
LastChapterResult
|
||||
LastChapterResult,
|
||||
SelectedChapterContentResult
|
||||
} from "../repositories/chapter.repository.js";
|
||||
import { ActChapter, ActStory } from "./Act.js";
|
||||
import ChapterContentRepository, {
|
||||
@@ -65,6 +68,13 @@ export interface CompleteChapterContent {
|
||||
version?: number;
|
||||
}
|
||||
|
||||
export interface ChapterExportInfo {
|
||||
chapterId: string;
|
||||
title: string;
|
||||
chapterOrder: number;
|
||||
availableVersions: number[];
|
||||
}
|
||||
|
||||
interface TipTapNode {
|
||||
type?: string;
|
||||
text?: string;
|
||||
@@ -602,4 +612,53 @@ export default class Chapter {
|
||||
|
||||
return processedChapters;
|
||||
}
|
||||
|
||||
static getChaptersExportInfo(userId: string, bookId: string, lang: 'fr' | 'en' = 'fr'): ChapterExportInfo[] {
|
||||
const results: ChapterExportInfoResult[] = ChapterRepo.fetchChaptersExportInfo(userId, bookId, lang);
|
||||
const userEncryptionKey: string = getUserEncryptionKey(userId);
|
||||
const exportInfos: ChapterExportInfo[] = [];
|
||||
|
||||
for (const result of results) {
|
||||
if (!result.available_versions) continue;
|
||||
const versions: number[] = result.available_versions
|
||||
.split(',')
|
||||
.map((v: string): number => parseInt(v, 10))
|
||||
.filter((v: number): boolean => !isNaN(v));
|
||||
if (versions.length === 0) continue;
|
||||
exportInfos.push({
|
||||
chapterId: result.chapter_id,
|
||||
title: result.title ? System.decryptDataWithUserKey(result.title, userEncryptionKey) : '',
|
||||
chapterOrder: result.chapter_order,
|
||||
availableVersions: versions.sort((a: number, b: number): number => a - b)
|
||||
});
|
||||
}
|
||||
|
||||
return exportInfos;
|
||||
}
|
||||
|
||||
static getCompleteBookDataWithSelections(userId: string, bookId: string, selections: ChapterSelectionParam[] | null, lang: 'fr' | 'en' = 'fr'): CompleteBookData {
|
||||
if (!selections || selections.length === 0) {
|
||||
return Book.completeBookData(userId, bookId, lang);
|
||||
}
|
||||
|
||||
const bookData: CompleteBookData = Book.completeBookData(userId, bookId, lang);
|
||||
const selectedResults: SelectedChapterContentResult[] = ChapterRepo.fetchSelectedChaptersContent(bookId, selections, lang);
|
||||
const userEncryptionKey: string = getUserEncryptionKey(userId);
|
||||
const selectedChapters: CompleteChapterContent[] = [];
|
||||
|
||||
for (const result of selectedResults) {
|
||||
selectedChapters.push({
|
||||
id: result.chapter_id,
|
||||
title: result.title ? System.decryptDataWithUserKey(result.title, userEncryptionKey) : '',
|
||||
content: result.content ? System.decryptDataWithUserKey(result.content, userEncryptionKey) : '',
|
||||
order: result.chapter_order,
|
||||
version: result.version
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
...bookData,
|
||||
chapters: selectedChapters
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user