Add enable/disable management for book tools (characters, worlds, and locations)
- Introduced toggling functionality for managing `characters`, `worlds`, and `locations` tool availability per book. - Updated `CharacterComponent`, `WorldSetting`, and `LocationComponent` with toggle switches for tool enablement. - Added `book_tools` database table and related schema migration for storing tool settings. - Extended API calls, models, and IPC handlers to support tool enablement states. - Localized new strings for English with supporting descriptions and messages. - Adjusted conditional rendering logic across components to respect tool enablement.
This commit is contained in:
@@ -3,6 +3,7 @@ import CharacterRepo, {
|
||||
CharacterResult,
|
||||
CompleteCharacterResult
|
||||
} from "../repositories/character.repository.js";
|
||||
import BookRepo, {BookToolsTable} from "../repositories/book.repository.js";
|
||||
import System from "../System.js";
|
||||
import {getUserEncryptionKey} from "../keyManager.js";
|
||||
|
||||
@@ -41,6 +42,11 @@ export interface CharacterProps {
|
||||
history: string;
|
||||
}
|
||||
|
||||
export interface CharacterListResponse {
|
||||
characters: CharacterProps[];
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
export interface CompleteCharacterProps {
|
||||
id?: string;
|
||||
name: string;
|
||||
@@ -87,11 +93,15 @@ export default class Character {
|
||||
* @param lang - The language code for localization (defaults to 'fr')
|
||||
* @returns An array of decrypted character properties
|
||||
*/
|
||||
public static getCharacterList(userId: string, bookId: string, lang: 'fr' | 'en' = 'fr'): CharacterProps[] {
|
||||
public static getCharacterList(userId: string, bookId: string, lang: 'fr' | 'en' = 'fr'): CharacterListResponse {
|
||||
const bookTools: BookToolsTable | null = BookRepo.fetchBookTools(userId, bookId, lang);
|
||||
const enabled: boolean = bookTools ? bookTools.characters_enabled === 1 : false;
|
||||
|
||||
const userEncryptionKey: string = getUserEncryptionKey(userId);
|
||||
const encryptedCharacters: CharacterResult[] = CharacterRepo.fetchCharacters(userId, bookId, lang);
|
||||
if (!encryptedCharacters) return [];
|
||||
if (encryptedCharacters.length === 0) return [];
|
||||
if (!encryptedCharacters || encryptedCharacters.length === 0) {
|
||||
return { characters: [], enabled };
|
||||
}
|
||||
const decryptedCharacterList: CharacterProps[] = [];
|
||||
for (const encryptedCharacter of encryptedCharacters) {
|
||||
decryptedCharacterList.push({
|
||||
@@ -106,7 +116,7 @@ export default class Character {
|
||||
history: encryptedCharacter.history ? System.decryptDataWithUserKey(encryptedCharacter.history, userEncryptionKey) : '',
|
||||
})
|
||||
}
|
||||
return decryptedCharacterList;
|
||||
return { characters: decryptedCharacterList, enabled };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -358,4 +368,5 @@ export default class Character {
|
||||
}).join('\n\n');
|
||||
return formattedCharactersDescription;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user