- Introduce new error messages for syncing and book deletion in `en.json`. - Update `DeleteBook` to support local-only deletion and synced book management. - Refine offline/online behavior with `deleteLocalToo` checkbox and update related state handling. - Extend repository and IPC methods to handle optional IDs for updates. - Add `SyncQueueContext` for queueing offline changes and improving synchronization workflows. - Enhance refined text generation logic in `DraftCompanion` and `GhostWriter` components. - Replace PUT with PATCH for world updates to align with API expectations. - Streamline `AlertBox` by integrating dynamic translation keys for deletion prompts.
77 lines
2.7 KiB
TypeScript
77 lines
2.7 KiB
TypeScript
import { ipcMain } from 'electron';
|
|
import { createHandler } from '../database/LocalSystem.js';
|
|
import Character from '../database/models/Character.js';
|
|
import type { CharacterProps, CharacterPropsPost, CharacterAttribute } from '../database/models/Character.js';
|
|
|
|
interface AddCharacterData {
|
|
character: CharacterPropsPost;
|
|
bookId: string;
|
|
id?: string;
|
|
}
|
|
|
|
interface AddAttributeData {
|
|
characterId: string;
|
|
type: string;
|
|
name: string;
|
|
id?: string;
|
|
}
|
|
|
|
// GET /character/list - Get character list
|
|
interface GetCharacterListData {
|
|
bookid: string;
|
|
}
|
|
ipcMain.handle('db:character:list', createHandler<GetCharacterListData, CharacterProps[]>(
|
|
function(userId: string, data: GetCharacterListData, lang: 'fr' | 'en'): CharacterProps[] {
|
|
return Character.getCharacterList(userId, data.bookid, lang);
|
|
}
|
|
)
|
|
);
|
|
|
|
// GET /character/attribute - Get character attributes
|
|
interface GetCharacterAttributesData {
|
|
characterId: string;
|
|
}
|
|
ipcMain.handle('db:character:attributes', createHandler<GetCharacterAttributesData, CharacterAttribute[]>(
|
|
function(userId: string, data: GetCharacterAttributesData, lang: 'fr' | 'en'): CharacterAttribute[] {
|
|
return Character.getAttributes(data.characterId, userId, lang);
|
|
}
|
|
)
|
|
);
|
|
|
|
// POST /character/add - Add new character
|
|
ipcMain.handle('db:character:create', createHandler<AddCharacterData, string>(
|
|
function(userId: string, data: AddCharacterData, lang: 'fr' | 'en'): string {
|
|
return Character.addNewCharacter(userId, data.character, data.bookId, lang, data.id);
|
|
}
|
|
)
|
|
);
|
|
|
|
// POST /character/attribute/add - Add attribute to character
|
|
ipcMain.handle('db:character:attribute:add', createHandler<AddAttributeData, string>(
|
|
function(userId: string, data: AddAttributeData, lang: 'fr' | 'en'): string {
|
|
return Character.addNewAttribute(data.characterId, userId, data.type, data.name, lang, data.id);
|
|
}
|
|
)
|
|
);
|
|
|
|
// DELETE /character/attribute/delete - Delete character attribute
|
|
interface DeleteAttributeData {
|
|
attributeId: string;
|
|
}
|
|
ipcMain.handle('db:character:attribute:delete', createHandler<DeleteAttributeData, boolean>(
|
|
function(userId: string, data: DeleteAttributeData, lang: 'fr' | 'en'): boolean {
|
|
return Character.deleteAttribute(userId, data.attributeId, lang);
|
|
}
|
|
)
|
|
);
|
|
|
|
// POST /character/update - Update character
|
|
interface UpdateCharacterData {
|
|
character: CharacterPropsPost;
|
|
}
|
|
ipcMain.handle('db:character:update', createHandler<UpdateCharacterData, boolean>(
|
|
function(userId: string, data: UpdateCharacterData, lang: 'fr' | 'en'): boolean {
|
|
return Character.updateCharacter(userId, data.character, lang);
|
|
}
|
|
)
|
|
); |