Refactor ipc/book.ipc.ts for streamlined IPC handlers and additional type definitions
- Reorganize and reformat IPC handlers for improved readability and structure. - Add missing type definitions for `StoryData`, `AddWorldElementData`, `SetAIGuideLineData`, and others. - Simplify handler functions by enforcing consistent parameter usage and return types. - Remove outdated comments, redundant logic, and placeholder TODOs.
This commit is contained in:
@@ -3,29 +3,6 @@ import { createHandler } from '../database/LocalSystem.js';
|
|||||||
import Book from '../database/models/Book.js';
|
import Book from '../database/models/Book.js';
|
||||||
import type { BookProps, GuideLine, GuideLineAI, Act, Issue, WorldProps } from '../database/models/Book.js';
|
import type { BookProps, GuideLine, GuideLineAI, Act, Issue, WorldProps } from '../database/models/Book.js';
|
||||||
|
|
||||||
// ============================================================
|
|
||||||
// 1. GET /books - Get all books
|
|
||||||
// ============================================================
|
|
||||||
ipcMain.handle('db:book:books', createHandler<void, BookProps[]>(
|
|
||||||
async function(userId: string, _body: void, lang: 'fr' | 'en'):Promise<BookProps[]> {
|
|
||||||
return await Book.getBooks(userId, lang);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
// ============================================================
|
|
||||||
// 2. GET /book/:id - Get single book
|
|
||||||
// ============================================================
|
|
||||||
ipcMain.handle('db:book:bookBasicInformation', createHandler<string, BookProps>(
|
|
||||||
async function(userId: string, bookId: string, lang: 'fr' | 'en'):Promise<BookProps> {
|
|
||||||
return await Book.getBook(bookId, userId);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
// ============================================================
|
|
||||||
// 3. POST /book/basic-information - Update book basic info
|
|
||||||
// ============================================================
|
|
||||||
interface UpdateBookBasicData {
|
interface UpdateBookBasicData {
|
||||||
title: string;
|
title: string;
|
||||||
subTitle: string;
|
subTitle: string;
|
||||||
@@ -35,41 +12,6 @@ interface UpdateBookBasicData {
|
|||||||
bookId: string;
|
bookId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
ipcMain.handle(
|
|
||||||
'db:book:updateBasicInformation',
|
|
||||||
createHandler<UpdateBookBasicData, boolean>(
|
|
||||||
function(userId: string, data: UpdateBookBasicData, lang: 'fr' | 'en') {
|
|
||||||
return Book.updateBookBasicInformation(
|
|
||||||
userId,
|
|
||||||
data.title,
|
|
||||||
data.subTitle,
|
|
||||||
data.summary,
|
|
||||||
data.publicationDate,
|
|
||||||
data.wordCount,
|
|
||||||
data.bookId,
|
|
||||||
lang
|
|
||||||
);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
// Frontend: invoke('db:book:updateBasicInformation', data)
|
|
||||||
|
|
||||||
// ============================================================
|
|
||||||
// 4. GET /book/guide-line - Get guideline
|
|
||||||
// ============================================================
|
|
||||||
ipcMain.handle(
|
|
||||||
'db:book:guideline:get',
|
|
||||||
createHandler<string, GuideLine | null>(
|
|
||||||
async function(userId: string, bookId: string, lang: 'fr' | 'en') {
|
|
||||||
return await Book.getGuideLine(userId, bookId, lang);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
// Frontend: invoke('db:book:guideline:get', bookId)
|
|
||||||
|
|
||||||
// ============================================================
|
|
||||||
// 5. POST /book/guide-line - Update guideline
|
|
||||||
// ============================================================
|
|
||||||
interface UpdateGuideLineData {
|
interface UpdateGuideLineData {
|
||||||
bookId: string;
|
bookId: string;
|
||||||
tone: string | null;
|
tone: string | null;
|
||||||
@@ -84,9 +26,94 @@ interface UpdateGuideLineData {
|
|||||||
intendedAudience: string | null;
|
intendedAudience: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface StoryData {
|
||||||
|
acts: Act[];
|
||||||
|
issues: Issue[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface CreateBookData {
|
||||||
|
title: string;
|
||||||
|
subTitle: string | null;
|
||||||
|
summary: string | null;
|
||||||
|
type: string;
|
||||||
|
serieId: number | null;
|
||||||
|
desiredReleaseDate: string | null;
|
||||||
|
desiredWordCount: number | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AddIncidentData {
|
||||||
|
bookId: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AddPlotPointData {
|
||||||
|
bookId: string;
|
||||||
|
name: string;
|
||||||
|
incidentId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AddIssueData {
|
||||||
|
bookId: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AddWorldData {
|
||||||
|
bookId: string;
|
||||||
|
worldName: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AddWorldElementData {
|
||||||
|
worldId: string;
|
||||||
|
elementName: string;
|
||||||
|
elementType: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SetAIGuideLineData {
|
||||||
|
bookId: string;
|
||||||
|
narrativeType: number;
|
||||||
|
dialogueType: number;
|
||||||
|
globalResume: string;
|
||||||
|
atmosphere: string;
|
||||||
|
verbeTense: number;
|
||||||
|
langue: number;
|
||||||
|
themes: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET /books - Get all books
|
||||||
|
ipcMain.handle('db:book:books', createHandler<void, BookProps[]>(
|
||||||
|
async function(userId: string, _body: void, lang: 'fr' | 'en'):Promise<BookProps[]> {
|
||||||
|
return await Book.getBooks(userId, lang);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// GET /book/:id - Get single book
|
||||||
|
ipcMain.handle('db:book:bookBasicInformation', createHandler<string, BookProps>(
|
||||||
|
async function(userId: string, bookId: string, lang: 'fr' | 'en'):Promise<BookProps> {
|
||||||
|
return await Book.getBook(bookId, userId);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// POST /book/basic-information - Update book basic info
|
||||||
|
ipcMain.handle('db:book:updateBasicInformation', createHandler<UpdateBookBasicData, boolean>(
|
||||||
|
function(userId: string, data: UpdateBookBasicData, lang: 'fr' | 'en') {
|
||||||
|
return Book.updateBookBasicInformation(userId, data.title, data.subTitle, data.summary, data.publicationDate, data.wordCount, data.bookId, lang);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// GET /book/guide-line - Get guideline
|
||||||
ipcMain.handle(
|
ipcMain.handle(
|
||||||
'db:book:guideline:update',
|
'db:book:guideline:get',
|
||||||
createHandler<UpdateGuideLineData, boolean>(
|
createHandler<string, GuideLine | null>(async function(userId: string, bookId: string, lang: 'fr' | 'en') {
|
||||||
|
return await Book.getGuideLine(userId, bookId, lang);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// POST /book/guide-line - Update guideline
|
||||||
|
ipcMain.handle('db:book:guideline:update', createHandler<UpdateGuideLineData, boolean>(
|
||||||
async function(userId: string, data: UpdateGuideLineData, lang: 'fr' | 'en') {
|
async function(userId: string, data: UpdateGuideLineData, lang: 'fr' | 'en') {
|
||||||
return await Book.updateGuideLine(
|
return await Book.updateGuideLine(
|
||||||
userId,
|
userId,
|
||||||
@@ -106,22 +133,12 @@ ipcMain.handle(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
// Frontend: invoke('db:book:guideline:update', data)
|
|
||||||
|
|
||||||
// ============================================================
|
// GET /book/story - Get story data (acts + issues)
|
||||||
// 6. GET /book/story - Get story data (acts + issues)
|
ipcMain.handle('db:book:story:get', createHandler<string, StoryData>(
|
||||||
// ============================================================
|
async function(userId: string, bookId: string, lang: 'fr' | 'en'):Promise<StoryData> {
|
||||||
interface StoryData {
|
const acts:Act[] = await Book.getActsData(userId, bookId, lang);
|
||||||
acts: Act[];
|
const issues:Issue[] = await Book.getIssuesFromBook(userId, bookId, lang);
|
||||||
issues: Issue[];
|
|
||||||
}
|
|
||||||
|
|
||||||
ipcMain.handle(
|
|
||||||
'db:book:story:get',
|
|
||||||
createHandler<string, StoryData>(
|
|
||||||
async function(userId: string, bookId: string, lang: 'fr' | 'en') {
|
|
||||||
const acts = await Book.getActsData(userId, bookId, lang);
|
|
||||||
const issues = await Book.getIssuesFromBook(userId, bookId, lang);
|
|
||||||
return {
|
return {
|
||||||
acts,
|
acts,
|
||||||
issues
|
issues
|
||||||
@@ -129,44 +146,9 @@ ipcMain.handle(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
// Frontend: invoke('db:book:story:get', bookId)
|
|
||||||
|
|
||||||
// ============================================================
|
// POST /book/add - Create new book
|
||||||
// 7. POST /book/story - Update story
|
ipcMain.handle('db:book:create', createHandler<CreateBookData, string>(
|
||||||
// TODO: Implement updateStory in Book.ts
|
|
||||||
// ============================================================
|
|
||||||
// interface StoryUpdateData {
|
|
||||||
// bookId: string;
|
|
||||||
// acts: Act[];
|
|
||||||
// mainChapters: ChapterProps[];
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// ipcMain.handle(
|
|
||||||
// 'db:book:story:update',
|
|
||||||
// createHandler<StoryUpdateData, boolean>(
|
|
||||||
// function(userId: string, data: StoryUpdateData, lang: 'fr' | 'en') {
|
|
||||||
// return Book.updateStory(userId, data.bookId, data.acts, data.mainChapters, lang);
|
|
||||||
// }
|
|
||||||
// )
|
|
||||||
// );
|
|
||||||
// // Frontend: invoke('db:book:story:update', data)
|
|
||||||
|
|
||||||
// ============================================================
|
|
||||||
// 8. POST /book/add - Create new book
|
|
||||||
// ============================================================
|
|
||||||
interface CreateBookData {
|
|
||||||
title: string;
|
|
||||||
subTitle: string | null;
|
|
||||||
summary: string | null;
|
|
||||||
type: string;
|
|
||||||
serieId: number | null;
|
|
||||||
desiredReleaseDate: string | null;
|
|
||||||
desiredWordCount: number | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
ipcMain.handle(
|
|
||||||
'db:book:create',
|
|
||||||
createHandler<CreateBookData, string>(
|
|
||||||
function(userId: string, data: CreateBookData, lang: 'fr' | 'en') {
|
function(userId: string, data: CreateBookData, lang: 'fr' | 'en') {
|
||||||
return Book.addBook(
|
return Book.addBook(
|
||||||
null,
|
null,
|
||||||
@@ -183,35 +165,9 @@ ipcMain.handle(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
// Frontend: invoke('db:book:create', data)
|
|
||||||
|
|
||||||
// ============================================================
|
|
||||||
// 9. POST /book/cover - Update book cover
|
|
||||||
// TODO: Implement updateBookCover in Book.ts
|
|
||||||
// ============================================================
|
|
||||||
// interface UpdateCoverData {
|
|
||||||
// bookId: string;
|
|
||||||
// coverImageName: string;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// ipcMain.handle(
|
|
||||||
// 'db:book:cover:update',
|
|
||||||
// createHandler<UpdateCoverData, boolean>(
|
|
||||||
// function(userId: string, data: UpdateCoverData, lang: 'fr' | 'en') {
|
|
||||||
// return Book.updateBookCover(userId, data.bookId, data.coverImageName, lang);
|
|
||||||
// }
|
|
||||||
// )
|
|
||||||
// );
|
|
||||||
// // Frontend: invoke('db:book:cover:update', { bookId, coverImageName })
|
|
||||||
|
|
||||||
// ============================================================
|
|
||||||
// 10. POST /book/incident/new - Add incident
|
|
||||||
// ============================================================
|
|
||||||
interface AddIncidentData {
|
|
||||||
bookId: string;
|
|
||||||
name: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// POST /book/incident/new - Add incident
|
||||||
ipcMain.handle(
|
ipcMain.handle(
|
||||||
'db:book:incident:add',
|
'db:book:incident:add',
|
||||||
createHandler<AddIncidentData, string>(
|
createHandler<AddIncidentData, string>(
|
||||||
@@ -220,38 +176,22 @@ ipcMain.handle(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
// Frontend: invoke('db:book:incident:add', { bookId, name })
|
|
||||||
|
|
||||||
// ============================================================
|
// DELETE /book/incident/remove - Remove incident
|
||||||
// 11. DELETE /book/incident/remove - Remove incident
|
|
||||||
// ============================================================
|
|
||||||
interface RemoveIncidentData {
|
interface RemoveIncidentData {
|
||||||
bookId: string;
|
bookId: string;
|
||||||
incidentId: string;
|
incidentId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
ipcMain.handle(
|
ipcMain.handle('db:book:incident:remove', createHandler<RemoveIncidentData, boolean>(
|
||||||
'db:book:incident:remove',
|
|
||||||
createHandler<RemoveIncidentData, boolean>(
|
|
||||||
function(userId: string, data: RemoveIncidentData, lang: 'fr' | 'en') {
|
function(userId: string, data: RemoveIncidentData, lang: 'fr' | 'en') {
|
||||||
return Book.removeIncident(userId, data.bookId, data.incidentId, lang);
|
return Book.removeIncident(userId, data.bookId, data.incidentId, lang);
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
// Frontend: invoke('db:book:incident:remove', { bookId, incidentId })
|
|
||||||
|
|
||||||
// ============================================================
|
// POST /book/plot/new - Add plot point
|
||||||
// 12. POST /book/plot/new - Add plot point
|
ipcMain.handle('db:book:plot:add', createHandler<AddPlotPointData, string>(
|
||||||
// ============================================================
|
|
||||||
interface AddPlotPointData {
|
|
||||||
bookId: string;
|
|
||||||
name: string;
|
|
||||||
incidentId: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
ipcMain.handle(
|
|
||||||
'db:book:plot:add',
|
|
||||||
createHandler<AddPlotPointData, string>(
|
|
||||||
function(userId: string, data: AddPlotPointData, lang: 'fr' | 'en') {
|
function(userId: string, data: AddPlotPointData, lang: 'fr' | 'en') {
|
||||||
return Book.addNewPlotPoint(
|
return Book.addNewPlotPoint(
|
||||||
userId,
|
userId,
|
||||||
@@ -263,11 +203,8 @@ ipcMain.handle(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
// Frontend: invoke('db:book:plot:add', { bookId, name, incidentId })
|
|
||||||
|
|
||||||
// ============================================================
|
// DELETE /book/plot/remove - Remove plot point
|
||||||
// 13. DELETE /book/plot/remove - Remove plot point
|
|
||||||
// ============================================================
|
|
||||||
ipcMain.handle(
|
ipcMain.handle(
|
||||||
'db:book:plot:remove',
|
'db:book:plot:remove',
|
||||||
createHandler<string, boolean>(
|
createHandler<string, boolean>(
|
||||||
@@ -276,82 +213,41 @@ ipcMain.handle(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
// Frontend: invoke('db:book:plot:remove', plotPointId)
|
|
||||||
|
|
||||||
// ============================================================
|
// POST /book/issue/add - Add issue
|
||||||
// 14. POST /book/issue/add - Add issue
|
ipcMain.handle('db:book:issue:add', createHandler<AddIssueData, string>(
|
||||||
// ============================================================
|
|
||||||
interface AddIssueData {
|
|
||||||
bookId: string;
|
|
||||||
name: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
ipcMain.handle(
|
|
||||||
'db:book:issue:add',
|
|
||||||
createHandler<AddIssueData, string>(
|
|
||||||
function(userId: string, data: AddIssueData, lang: 'fr' | 'en') {
|
function(userId: string, data: AddIssueData, lang: 'fr' | 'en') {
|
||||||
return Book.addNewIssue(userId, data.bookId, data.name, lang);
|
return Book.addNewIssue(userId, data.bookId, data.name, lang);
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
// Frontend: invoke('db:book:issue:add', { bookId, name })
|
|
||||||
|
|
||||||
// ============================================================
|
// DELETE /book/issue/remove - Remove issue
|
||||||
// 15. DELETE /book/issue/remove - Remove issue
|
ipcMain.handle('db:book:issue:remove', createHandler<string, boolean>(
|
||||||
// ============================================================
|
|
||||||
ipcMain.handle(
|
|
||||||
'db:book:issue:remove',
|
|
||||||
createHandler<string, boolean>(
|
|
||||||
function(userId: string, issueId: string, lang: 'fr' | 'en') {
|
function(userId: string, issueId: string, lang: 'fr' | 'en') {
|
||||||
return Book.removeIssue(userId, issueId, lang);
|
return Book.removeIssue(userId, issueId, lang);
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
// Frontend: invoke('db:book:issue:remove', issueId)
|
|
||||||
|
|
||||||
// ============================================================
|
// GET /book/worlds - Get worlds for book
|
||||||
// 16. GET /book/worlds - Get worlds for book
|
ipcMain.handle('db:book:worlds:get', createHandler<string, WorldProps[]>(
|
||||||
// ============================================================
|
|
||||||
ipcMain.handle(
|
|
||||||
'db:book:worlds:get',
|
|
||||||
createHandler<string, WorldProps[]>(
|
|
||||||
function(userId: string, bookId: string, lang: 'fr' | 'en') {
|
function(userId: string, bookId: string, lang: 'fr' | 'en') {
|
||||||
return Book.getWorlds(userId, bookId, lang);
|
return Book.getWorlds(userId, bookId, lang);
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
// Frontend: invoke('db:book:worlds:get', bookId)
|
|
||||||
|
|
||||||
// ============================================================
|
// POST /book/world/add - Add world
|
||||||
// 17. POST /book/world/add - Add world
|
ipcMain.handle('db:book:world:add', createHandler<AddWorldData, string>(
|
||||||
// ============================================================
|
|
||||||
interface AddWorldData {
|
|
||||||
bookId: string;
|
|
||||||
worldName: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
ipcMain.handle(
|
|
||||||
'db:book:world:add',
|
|
||||||
createHandler<AddWorldData, string>(
|
|
||||||
function(userId: string, data: AddWorldData, lang: 'fr' | 'en') {
|
function(userId: string, data: AddWorldData, lang: 'fr' | 'en') {
|
||||||
return Book.addNewWorld(userId, data.bookId, data.worldName, lang);
|
return Book.addNewWorld(userId, data.bookId, data.worldName, lang);
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
// Frontend: invoke('db:book:world:add', { bookId, worldName })
|
|
||||||
|
|
||||||
// ============================================================
|
// POST /book/world/element/add - Add element to world
|
||||||
// 18. POST /book/world/element/add - Add element to world
|
ipcMain.handle('db:book:world:element:add', createHandler<AddWorldElementData, string>(
|
||||||
// ============================================================
|
|
||||||
interface AddWorldElementData {
|
|
||||||
worldId: string;
|
|
||||||
elementName: string;
|
|
||||||
elementType: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
ipcMain.handle(
|
|
||||||
'db:book:world:element:add',
|
|
||||||
createHandler<AddWorldElementData, string>(
|
|
||||||
function(userId: string, data: AddWorldElementData, lang: 'fr' | 'en') {
|
function(userId: string, data: AddWorldElementData, lang: 'fr' | 'en') {
|
||||||
return Book.addNewElementToWorld(
|
return Book.addNewElementToWorld(
|
||||||
userId,
|
userId,
|
||||||
@@ -363,92 +259,32 @@ ipcMain.handle(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
// Frontend: invoke('db:book:world:element:add', { worldId, elementName, elementType })
|
// DELETE /book/world/element/delete - Remove element from world
|
||||||
|
ipcMain.handle('db:book:world:element:remove', createHandler<string, boolean>(
|
||||||
// ============================================================
|
|
||||||
// 19. DELETE /book/world/element/delete - Remove element from world
|
|
||||||
// ============================================================
|
|
||||||
ipcMain.handle(
|
|
||||||
'db:book:world:element:remove',
|
|
||||||
createHandler<string, boolean>(
|
|
||||||
function(userId: string, elementId: string, lang: 'fr' | 'en') {
|
function(userId: string, elementId: string, lang: 'fr' | 'en') {
|
||||||
return Book.removeElementFromWorld(userId, elementId, lang);
|
return Book.removeElementFromWorld(userId, elementId, lang);
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
// Frontend: invoke('db:book:world:element:remove', elementId)
|
|
||||||
|
|
||||||
// ============================================================
|
// DELETE /book/delete - Delete book
|
||||||
// 20. PUT /book/world/update - Update world
|
ipcMain.handle('db:book:delete', createHandler<string, boolean>(
|
||||||
// TODO: Implement updateWorld in Book.ts
|
|
||||||
// ============================================================
|
|
||||||
// ipcMain.handle(
|
|
||||||
// 'db:book:world:update',
|
|
||||||
// createHandler<WorldProps, boolean>(
|
|
||||||
// function(userId: string, world: WorldProps, lang: 'fr' | 'en') {
|
|
||||||
// return Book.updateWorld(userId, world, lang);
|
|
||||||
// }
|
|
||||||
// )
|
|
||||||
// );
|
|
||||||
// // Frontend: invoke('db:book:world:update', worldData)
|
|
||||||
|
|
||||||
// ============================================================
|
|
||||||
// 21. DELETE /book/cover/delete - Delete book cover
|
|
||||||
// TODO: Implement deleteCoverPicture in Book.ts
|
|
||||||
// ============================================================
|
|
||||||
// ipcMain.handle(
|
|
||||||
// 'db:book:cover:delete',
|
|
||||||
// createHandler<string, boolean>(
|
|
||||||
// function(userId: string, bookId: string, lang: 'fr' | 'en') {
|
|
||||||
// return Book.deleteCoverPicture(userId, bookId, lang);
|
|
||||||
// }
|
|
||||||
// )
|
|
||||||
// );
|
|
||||||
// // Frontend: invoke('db:book:cover:delete', bookId)
|
|
||||||
|
|
||||||
// ============================================================
|
|
||||||
// 22. DELETE /book/delete - Delete book
|
|
||||||
// ============================================================
|
|
||||||
ipcMain.handle(
|
|
||||||
'db:book:delete',
|
|
||||||
createHandler<string, boolean>(
|
|
||||||
function(userId: string, bookId: string, lang: 'fr' | 'en') {
|
function(userId: string, bookId: string, lang: 'fr' | 'en') {
|
||||||
return Book.removeBook(userId, bookId, lang);
|
return Book.removeBook(userId, bookId, lang);
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
// Frontend: invoke('db:book:delete', bookId)
|
|
||||||
|
|
||||||
// ============================================================
|
// GET /book/ai/guideline - Get AI guideline
|
||||||
// 23. GET /book/ai/guideline - Get AI guideline
|
ipcMain.handle('db:book:guideline:ai:get', createHandler<string, GuideLineAI>(
|
||||||
// ============================================================
|
|
||||||
ipcMain.handle(
|
|
||||||
'db:book:guideline:ai:get',
|
|
||||||
createHandler<string, GuideLineAI>(
|
|
||||||
function(userId: string, bookId: string, lang: 'fr' | 'en') {
|
function(userId: string, bookId: string, lang: 'fr' | 'en') {
|
||||||
return Book.getGuideLineAI(bookId, userId, lang);
|
return Book.getGuideLineAI(bookId, userId, lang);
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
// Frontend: invoke('db:book:guideline:ai:get', bookId)
|
|
||||||
|
|
||||||
// ============================================================
|
// POST /book/ai/guideline (set) - Set AI guideline
|
||||||
// 24. POST /book/ai/guideline (set) - Set AI guideline
|
ipcMain.handle('db:book:guideline:ai:set', createHandler<SetAIGuideLineData, boolean>(
|
||||||
// ============================================================
|
|
||||||
interface SetAIGuideLineData {
|
|
||||||
bookId: string;
|
|
||||||
narrativeType: number;
|
|
||||||
dialogueType: number;
|
|
||||||
globalResume: string;
|
|
||||||
atmosphere: string;
|
|
||||||
verbeTense: number;
|
|
||||||
langue: number;
|
|
||||||
themes: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
ipcMain.handle(
|
|
||||||
'db:book:guideline:ai:set',
|
|
||||||
createHandler<SetAIGuideLineData, boolean>(
|
|
||||||
function(userId: string, data: SetAIGuideLineData, lang: 'fr' | 'en') {
|
function(userId: string, data: SetAIGuideLineData, lang: 'fr' | 'en') {
|
||||||
return Book.setAIGuideLine(
|
return Book.setAIGuideLine(
|
||||||
data.bookId,
|
data.bookId,
|
||||||
@@ -465,69 +301,3 @@ ipcMain.handle(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
// Frontend: invoke('db:book:guideline:ai:set', data)
|
|
||||||
|
|
||||||
// ============================================================
|
|
||||||
// 25. GET /book/transform/epub - Export to EPUB
|
|
||||||
// TODO: Implement transformToEpub in Book.ts
|
|
||||||
// ============================================================
|
|
||||||
// ipcMain.handle(
|
|
||||||
// 'db:book:export:epub',
|
|
||||||
// createHandler<string, ExportData>(
|
|
||||||
// function(userId: string, bookId: string, lang: 'fr' | 'en') {
|
|
||||||
// return Book.transformToEpub(userId, bookId, lang);
|
|
||||||
// }
|
|
||||||
// )
|
|
||||||
// );
|
|
||||||
// // Frontend: invoke('db:book:export:epub', bookId)
|
|
||||||
|
|
||||||
// ============================================================
|
|
||||||
// 26. GET /book/transform/pdf - Export to PDF
|
|
||||||
// TODO: Implement transformToPDF in Book.ts
|
|
||||||
// ============================================================
|
|
||||||
// ipcMain.handle(
|
|
||||||
// 'db:book:export:pdf',
|
|
||||||
// createHandler<string, ExportData>(
|
|
||||||
// function(userId: string, bookId: string, lang: 'fr' | 'en') {
|
|
||||||
// return Book.transformToPDF(userId, bookId, lang);
|
|
||||||
// }
|
|
||||||
// )
|
|
||||||
// );
|
|
||||||
// // Frontend: invoke('db:book:export:pdf', bookId)
|
|
||||||
|
|
||||||
// ============================================================
|
|
||||||
// 27. GET /book/transform/docx - Export to DOCX
|
|
||||||
// TODO: Implement transformToDOCX in Book.ts
|
|
||||||
// ============================================================
|
|
||||||
// ipcMain.handle(
|
|
||||||
// 'db:book:export:docx',
|
|
||||||
// createHandler<string, ExportData>(
|
|
||||||
// function(userId: string, bookId: string, lang: 'fr' | 'en') {
|
|
||||||
// return Book.transformToDOCX(userId, bookId, lang);
|
|
||||||
// }
|
|
||||||
// )
|
|
||||||
// );
|
|
||||||
// // Frontend: invoke('db:book:export:docx', bookId)
|
|
||||||
|
|
||||||
// ============================================================
|
|
||||||
// 28. GET /book/tags - Get tags from book
|
|
||||||
// TODO: Implement getTagsFromBook in Book.ts
|
|
||||||
// ============================================================
|
|
||||||
// interface BookTags {
|
|
||||||
// characters: Tag[];
|
|
||||||
// locations: Tag[];
|
|
||||||
// objects: Tag[];
|
|
||||||
// worldElements: Tag[];
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// ipcMain.handle(
|
|
||||||
// 'db:book:tags:get',
|
|
||||||
// createHandler<string, BookTags>(
|
|
||||||
// function(userId: string, bookId: string, lang: 'fr' | 'en') {
|
|
||||||
// return Book.getTagsFromBook(userId, bookId, lang);
|
|
||||||
// }
|
|
||||||
// )
|
|
||||||
// );
|
|
||||||
// // Frontend: invoke('db:book:tags:get', bookId)
|
|
||||||
|
|
||||||
console.log('[IPC] Book handlers registered');
|
|
||||||
|
|||||||
Reference in New Issue
Block a user