Add support for syncing tool settings with lastUpdate and improve consistency

- Introduced `lastUpdate` field in `book_tools` for tracking changes.
- Refactored tool enablement logic in `CharacterComponent`, `WorldSetting`, and `LocationComponent` for consistency.
- Updated database schema and migration scripts for `book_tools` table.
- Enhanced synchronization workflows to support new `lastUpdate` logic.
- Adjusted related models, repositories, and IPC handlers for streamlined management.
- Improved type safety and robustness in tool-related methods with additional checks.
This commit is contained in:
natreex
2026-01-15 18:35:48 -05:00
parent ac968b7764
commit 2e6b30c632
12 changed files with 252 additions and 226 deletions

View File

@@ -1,6 +1,6 @@
import System from '../System.js';
import { getUserEncryptionKey } from '../keyManager.js';
import BookRepo, { BookQuery, BookToolsTable, BookToolsSettings, EritBooksTable } from "../repositories/book.repository.js";
import BookRepo, { BookQuery, BookToolsTable, EritBooksTable } from "../repositories/book.repository.js";
import { BookActSummariesTable } from "../repositories/act.repository.js";
import { BookAIGuideLineTable, BookGuideLineTable } from "../repositories/guideline.repository.js";
import ChapterRepo, {
@@ -35,9 +35,13 @@ import Cover from "./Cover.js";
import UserRepo from "../repositories/user.repository.js";
export interface SyncedBookTools {
charactersEnabled: boolean;
worldsEnabled: boolean;
locationsEnabled: boolean;
lastUpdate: number;
}
export interface BookToolsSettings {
characters: boolean;
worlds: boolean;
locations: boolean;
}
export interface BookProps {
@@ -308,7 +312,7 @@ export default class Book {
public static updateBookToolSetting(userId: string, bookId: string, toolName: 'characters' | 'worlds' | 'locations', enabled: boolean, lang: 'fr' | 'en' = 'fr'): boolean {
const columnName: 'characters_enabled' | 'worlds_enabled' | 'locations_enabled' = `${toolName}_enabled` as 'characters_enabled' | 'worlds_enabled' | 'locations_enabled';
return BookRepo.updateBookToolSetting(userId, bookId, columnName, enabled, lang);
return BookRepo.updateBookToolSetting(userId, bookId, columnName, enabled, System.timeStampInSeconds(), lang);
}
/**