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:
@@ -1,3 +1,7 @@
|
||||
export interface SyncedBookTools {
|
||||
lastUpdate: number;
|
||||
}
|
||||
|
||||
export interface SyncedBook {
|
||||
id: string;
|
||||
type: string;
|
||||
@@ -14,6 +18,7 @@ export interface SyncedBook {
|
||||
actSummaries: SyncedActSummary[];
|
||||
guideLine: SyncedGuideLine | null;
|
||||
aiGuideLine: SyncedAIGuideLine | null;
|
||||
bookTools: SyncedBookTools | null;
|
||||
}
|
||||
|
||||
export interface SyncedChapter {
|
||||
@@ -129,6 +134,7 @@ export interface BookSyncCompare {
|
||||
actSummaries: string[];
|
||||
guideLine: boolean;
|
||||
aiGuideLine: boolean;
|
||||
bookTools: boolean;
|
||||
}
|
||||
|
||||
export function compareBookSyncs(newerBook: SyncedBook, olderBook: SyncedBook): BookSyncCompare | null {
|
||||
@@ -148,6 +154,7 @@ export function compareBookSyncs(newerBook: SyncedBook, olderBook: SyncedBook):
|
||||
const changedActSummaryIds: string[] = [];
|
||||
let guideLineChanged: boolean = false;
|
||||
let aiGuideLineChanged: boolean = false;
|
||||
let bookToolsChanged: boolean = false;
|
||||
|
||||
newerBook.chapters.forEach((newerChapter: SyncedChapter): void => {
|
||||
const olderChapter: SyncedChapter | undefined = olderBook.chapters.find((chapter: SyncedChapter): boolean => chapter.id === newerChapter.id);
|
||||
@@ -296,6 +303,12 @@ export function compareBookSyncs(newerBook: SyncedBook, olderBook: SyncedBook):
|
||||
aiGuideLineChanged = true;
|
||||
}
|
||||
|
||||
if (newerBook.bookTools && olderBook.bookTools) {
|
||||
bookToolsChanged = newerBook.bookTools.lastUpdate > olderBook.bookTools.lastUpdate;
|
||||
} else if (newerBook.bookTools && !olderBook.bookTools) {
|
||||
bookToolsChanged = true;
|
||||
}
|
||||
|
||||
const hasChanges: boolean =
|
||||
changedChapterIds.length > 0 ||
|
||||
changedChapterContentIds.length > 0 ||
|
||||
@@ -312,7 +325,8 @@ export function compareBookSyncs(newerBook: SyncedBook, olderBook: SyncedBook):
|
||||
changedIssueIds.length > 0 ||
|
||||
changedActSummaryIds.length > 0 ||
|
||||
guideLineChanged ||
|
||||
aiGuideLineChanged;
|
||||
aiGuideLineChanged ||
|
||||
bookToolsChanged;
|
||||
|
||||
if (!hasChanges) {
|
||||
return null;
|
||||
@@ -335,6 +349,7 @@ export function compareBookSyncs(newerBook: SyncedBook, olderBook: SyncedBook):
|
||||
issues: changedIssueIds,
|
||||
actSummaries: changedActSummaryIds,
|
||||
guideLine: guideLineChanged,
|
||||
aiGuideLine: aiGuideLineChanged
|
||||
aiGuideLine: aiGuideLineChanged,
|
||||
bookTools: bookToolsChanged
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user