Add synchronization support for guidelines and AI guidelines
- Implemented syncing for `GuideLine` and `AIGuideLine` entities with encryption and decryption workflows. - Refined `GuidelineRepo` methods to check existence and update/insert records for both guideline types. - Updated timestamp handling in `GuideLine` and `AIGuideLine` models for accurate tracking. - Corrected QuillSense localization keys for labels and descriptions. - Improved database queries and modularized logic for consistency.
This commit is contained in:
@@ -174,10 +174,8 @@ export default class Act {
|
||||
for (const chapter of mainChapters) {
|
||||
const chapterId: string = chapter.chapterId;
|
||||
const chapterTitle: string = chapter.title;
|
||||
const hashedChapterTitle: string = System.hashElement(chapterTitle);
|
||||
const encryptedChapterTitle: string = System.encryptDataWithUserKey(chapterTitle, userEncryptionKey);
|
||||
const chapterOrder: number = chapter.chapterOrder;
|
||||
ChapterRepo.updateChapter(userId, chapterId, encryptedChapterTitle, hashedChapterTitle, chapterOrder, System.timeStampInSeconds(), lang);
|
||||
Chapter.updateChapter(userId, chapterId, chapterTitle, chapterOrder, lang);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -120,6 +120,7 @@ export default class GuideLine {
|
||||
encryptedPacing,
|
||||
encryptedKeyMessages,
|
||||
encryptedIntendedAudience,
|
||||
System.timeStampInSeconds(),
|
||||
lang
|
||||
);
|
||||
}
|
||||
@@ -210,6 +211,7 @@ export default class GuideLine {
|
||||
verbTense,
|
||||
language,
|
||||
encryptedThemes,
|
||||
System.timeStampInSeconds(),
|
||||
lang
|
||||
);
|
||||
}
|
||||
|
||||
@@ -303,6 +303,41 @@ export default class Sync {
|
||||
}
|
||||
}
|
||||
|
||||
if (syncCompareData.guideLine) {
|
||||
const guidelineResults: BookGuideLineTable[] = await GuidelineRepo.fetchBookGuideLineTable(userId, syncCompareData.id, lang);
|
||||
if (guidelineResults.length > 0) {
|
||||
const guidelineRecord: BookGuideLineTable = guidelineResults[0];
|
||||
decryptedGuideLines.push({
|
||||
...guidelineRecord,
|
||||
tone: guidelineRecord.tone ? System.decryptDataWithUserKey(guidelineRecord.tone, userEncryptionKey) : null,
|
||||
atmosphere: guidelineRecord.atmosphere ? System.decryptDataWithUserKey(guidelineRecord.atmosphere, userEncryptionKey) : null,
|
||||
writing_style: guidelineRecord.writing_style ? System.decryptDataWithUserKey(guidelineRecord.writing_style, userEncryptionKey) : null,
|
||||
themes: guidelineRecord.themes ? System.decryptDataWithUserKey(guidelineRecord.themes, userEncryptionKey) : null,
|
||||
symbolism: guidelineRecord.symbolism ? System.decryptDataWithUserKey(guidelineRecord.symbolism, userEncryptionKey) : null,
|
||||
motifs: guidelineRecord.motifs ? System.decryptDataWithUserKey(guidelineRecord.motifs, userEncryptionKey) : null,
|
||||
narrative_voice: guidelineRecord.narrative_voice ? System.decryptDataWithUserKey(guidelineRecord.narrative_voice, userEncryptionKey) : null,
|
||||
pacing: guidelineRecord.pacing ? System.decryptDataWithUserKey(guidelineRecord.pacing, userEncryptionKey) : null,
|
||||
intended_audience: guidelineRecord.intended_audience ? System.decryptDataWithUserKey(guidelineRecord.intended_audience, userEncryptionKey) : null,
|
||||
key_messages: guidelineRecord.key_messages ? System.decryptDataWithUserKey(guidelineRecord.key_messages, userEncryptionKey) : null
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (syncCompareData.aiGuideLine) {
|
||||
const aiGuidelineResults: BookAIGuideLineTable[] = await GuidelineRepo.fetchBookAIGuideLine(userId, syncCompareData.id, lang);
|
||||
if (aiGuidelineResults.length > 0) {
|
||||
const aiGuidelineRecord: BookAIGuideLineTable = aiGuidelineResults[0];
|
||||
decryptedAIGuideLines.push({
|
||||
...aiGuidelineRecord,
|
||||
global_resume: aiGuidelineRecord.global_resume ? System.decryptDataWithUserKey(aiGuidelineRecord.global_resume, userEncryptionKey) : null,
|
||||
themes: aiGuidelineRecord.themes ? System.decryptDataWithUserKey(aiGuidelineRecord.themes, userEncryptionKey) : null,
|
||||
tone: aiGuidelineRecord.tone ? System.decryptDataWithUserKey(aiGuidelineRecord.tone, userEncryptionKey) : null,
|
||||
atmosphere: aiGuidelineRecord.atmosphere ? System.decryptDataWithUserKey(aiGuidelineRecord.atmosphere, userEncryptionKey) : null,
|
||||
current_resume: aiGuidelineRecord.current_resume ? System.decryptDataWithUserKey(aiGuidelineRecord.current_resume, userEncryptionKey) : null
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const bookResults: EritBooksTable[] = await BookRepo.fetchCompleteBookById(syncCompareData.id, lang);
|
||||
if (bookResults.length > 0) {
|
||||
const bookRecord: EritBooksTable = bookResults[0];
|
||||
@@ -361,6 +396,8 @@ export default class Sync {
|
||||
const serverWorlds: BookWorldTable[] = completeBook.worlds;
|
||||
const serverWorldElements: BookWorldElementsTable[] = completeBook.worldElements;
|
||||
const serverIssues: BookIssuesTable[] = completeBook.issues;
|
||||
const serverGuideLines: BookGuideLineTable[] = completeBook.guideLine;
|
||||
const serverAIGuideLines: BookAIGuideLineTable[] = completeBook.aiGuideLine;
|
||||
|
||||
const bookId: string = completeBook.eritBooks.length > 0 ? completeBook.eritBooks[0].book_id : '';
|
||||
|
||||
@@ -638,6 +675,55 @@ export default class Sync {
|
||||
}
|
||||
}
|
||||
|
||||
if (serverGuideLines && serverGuideLines.length > 0) {
|
||||
for (const serverGuideLine of serverGuideLines) {
|
||||
const guideLineExists: boolean = GuidelineRepo.guideLineExist(userId, bookId, lang);
|
||||
const encryptedTone: string | null = serverGuideLine.tone ? System.encryptDataWithUserKey(serverGuideLine.tone, userEncryptionKey) : null;
|
||||
const encryptedAtmosphere: string | null = serverGuideLine.atmosphere ? System.encryptDataWithUserKey(serverGuideLine.atmosphere, userEncryptionKey) : null;
|
||||
const encryptedWritingStyle: string | null = serverGuideLine.writing_style ? System.encryptDataWithUserKey(serverGuideLine.writing_style, userEncryptionKey) : null;
|
||||
const encryptedThemes: string | null = serverGuideLine.themes ? System.encryptDataWithUserKey(serverGuideLine.themes, userEncryptionKey) : null;
|
||||
const encryptedSymbolism: string | null = serverGuideLine.symbolism ? System.encryptDataWithUserKey(serverGuideLine.symbolism, userEncryptionKey) : null;
|
||||
const encryptedMotifs: string | null = serverGuideLine.motifs ? System.encryptDataWithUserKey(serverGuideLine.motifs, userEncryptionKey) : null;
|
||||
const encryptedNarrativeVoice: string | null = serverGuideLine.narrative_voice ? System.encryptDataWithUserKey(serverGuideLine.narrative_voice, userEncryptionKey) : null;
|
||||
const encryptedPacing: string | null = serverGuideLine.pacing ? System.encryptDataWithUserKey(serverGuideLine.pacing, userEncryptionKey) : null;
|
||||
const encryptedKeyMessages: string | null = serverGuideLine.key_messages ? System.encryptDataWithUserKey(serverGuideLine.key_messages, userEncryptionKey) : null;
|
||||
const encryptedIntendedAudience: string | null = serverGuideLine.intended_audience ? System.encryptDataWithUserKey(serverGuideLine.intended_audience, userEncryptionKey) : null;
|
||||
if (guideLineExists) {
|
||||
const updateSuccessful: boolean = GuidelineRepo.updateGuideLine(userId, bookId, encryptedTone, encryptedAtmosphere, encryptedWritingStyle, encryptedThemes, encryptedSymbolism, encryptedMotifs, encryptedNarrativeVoice, encryptedPacing, encryptedKeyMessages, encryptedIntendedAudience, serverGuideLine.last_update, lang);
|
||||
if (!updateSuccessful) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
const insertSuccessful: boolean = GuidelineRepo.insertSyncGuideLine(userId, bookId, encryptedTone, encryptedAtmosphere, encryptedWritingStyle, encryptedThemes, encryptedSymbolism, encryptedMotifs, encryptedNarrativeVoice, encryptedPacing, encryptedIntendedAudience, encryptedKeyMessages, serverGuideLine.last_update, lang);
|
||||
if (!insertSuccessful) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (serverAIGuideLines && serverAIGuideLines.length > 0) {
|
||||
for (const serverAIGuideLine of serverAIGuideLines) {
|
||||
const aiGuideLineExists: boolean = GuidelineRepo.aiGuideLineExist(userId, bookId, lang);
|
||||
const encryptedGlobalResume: string | null = serverAIGuideLine.global_resume ? System.encryptDataWithUserKey(serverAIGuideLine.global_resume, userEncryptionKey) : null;
|
||||
const encryptedThemes: string | null = serverAIGuideLine.themes ? System.encryptDataWithUserKey(serverAIGuideLine.themes, userEncryptionKey) : null;
|
||||
const encryptedTone: string | null = serverAIGuideLine.tone ? System.encryptDataWithUserKey(serverAIGuideLine.tone, userEncryptionKey) : null;
|
||||
const encryptedAtmosphere: string | null = serverAIGuideLine.atmosphere ? System.encryptDataWithUserKey(serverAIGuideLine.atmosphere, userEncryptionKey) : null;
|
||||
const encryptedCurrentResume: string | null = serverAIGuideLine.current_resume ? System.encryptDataWithUserKey(serverAIGuideLine.current_resume, userEncryptionKey) : null;
|
||||
if (aiGuideLineExists) {
|
||||
const updateSuccessful: boolean = GuidelineRepo.insertAIGuideLine(userId, bookId, serverAIGuideLine.narrative_type, serverAIGuideLine.dialogue_type, encryptedGlobalResume, encryptedAtmosphere, serverAIGuideLine.verbe_tense, serverAIGuideLine.langue, encryptedThemes, serverAIGuideLine.last_update, lang);
|
||||
if (!updateSuccessful) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
const insertSuccessful: boolean = GuidelineRepo.insertSyncAIGuideLine(userId, bookId, encryptedGlobalResume, encryptedThemes, serverAIGuideLine.verbe_tense, serverAIGuideLine.narrative_type, serverAIGuideLine.langue, serverAIGuideLine.dialogue_type, encryptedTone, encryptedAtmosphere, encryptedCurrentResume, serverAIGuideLine.last_update, lang);
|
||||
if (!insertSuccessful) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -703,8 +789,8 @@ export default class Sync {
|
||||
PlotPointRepository.fetchSyncedPlotPoints(userId, lang),
|
||||
IssueRepository.fetchSyncedIssues(userId, lang),
|
||||
ActRepository.fetchSyncedActSummaries(userId, lang),
|
||||
GuidelineRepo.fetchSyncedAIGuideLine(userId, lang),
|
||||
GuidelineRepo.fetchSyncedGuideLine(userId, lang)
|
||||
GuidelineRepo.fetchSyncedGuideLine(userId, lang),
|
||||
GuidelineRepo.fetchSyncedAIGuideLine(userId, lang)
|
||||
]);
|
||||
|
||||
return allBooks.map((bookRecord: SyncedBookResult): SyncedBook => {
|
||||
|
||||
Reference in New Issue
Block a user