Add BooksSyncContext, refine database schema, and enhance synchronization support
- Introduce `BooksSyncContext` for managing book synchronization states (server-only, local-only, to-sync, etc.). - Remove `UserContext` and related dependencies. - Refine localization strings (`en.json`) with sync-related updates (e.g., "toSyncFromServer", "toSyncToServer"). - Extend database schema with additional tables and fields for syncing books, chapters, and related entities. - Add `last_update` fields and update corresponding repository methods to support synchronization logic. - Enhance IPC handlers with stricter typing, data validation, and sync-aware operations.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { ipcMain } from 'electron';
|
||||
import { createHandler } from '../database/LocalSystem.js';
|
||||
import Book from '../database/models/Book.js';
|
||||
import Book, {CompleteBook, SyncedBook} from '../database/models/Book.js';
|
||||
import type { BookProps, GuideLine, GuideLineAI, Act, Issue, WorldProps } from '../database/models/Book.js';
|
||||
import Chapter from '../database/models/Chapter.js';
|
||||
import type { ChapterProps } from '../database/models/Chapter.js';
|
||||
@@ -88,6 +88,10 @@ interface SetAIGuideLineData {
|
||||
themes: string;
|
||||
}
|
||||
|
||||
interface GetGuidelineData {
|
||||
id: 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[]> {
|
||||
@@ -96,6 +100,20 @@ ipcMain.handle('db:book:books', createHandler<void, BookProps[]>(
|
||||
)
|
||||
);
|
||||
|
||||
// GET /books/synced - Get all synced books
|
||||
ipcMain.handle('db:books:synced', createHandler<void, SyncedBook[]>(
|
||||
async function(userId: string, _body: void, lang: 'fr' | 'en'):Promise<SyncedBook[]> {
|
||||
return await Book.getSyncedBooks(userId, lang);
|
||||
})
|
||||
);
|
||||
|
||||
// POST /book/sync/save - Save complete book
|
||||
ipcMain.handle('db:book:syncSave', createHandler<CompleteBook, boolean>(
|
||||
async function(userId: string, data: CompleteBook, lang: 'fr' | 'en'):Promise<boolean> {
|
||||
return await Book.saveCompleteBook(userId, data, 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> {
|
||||
@@ -113,11 +131,7 @@ ipcMain.handle('db:book:updateBasicInformation', createHandler<UpdateBookBasicDa
|
||||
);
|
||||
|
||||
// GET /book/guide-line - Get guideline
|
||||
interface GetGuidelineData {
|
||||
id: string;
|
||||
}
|
||||
ipcMain.handle(
|
||||
'db:book:guideline:get',
|
||||
ipcMain.handle('db:book:guideline:get',
|
||||
createHandler<GetGuidelineData, GuideLine | null>(async function(userId: string, data: GetGuidelineData, lang: 'fr' | 'en') {
|
||||
return await Book.getGuideLine(userId, data.id, lang);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user