feat(desktop): two-way cloud sync with mobile and web

Rewrites the desktop mirror as services/sync/SyncEngine: a persistent
outbox, per-account server-clock keyset cursors with paging, pulls that never
overwrite unsent local edits, deletions both ways through sync_tombstones and
per-row failure isolation. It now covers history titles and favorites,
dictionary, every meeting's memos and documents, memo tags, user commands and
dictation/meeting templates, and registers the desktop as a device that the
phone can disconnect.

Fixes shipped defects: the first pull after sign-in fetched nothing, only
the first meeting's children were pushed, team meetings leaked into the
personal database and lost team_id on re-push, and Realtime never connected
because Electron's Node 20 has no global WebSocket (ws is now the transport).
Anonymous local-mode records are imported into the first account that signs
in. The settings sync section is translated and shows pending/rejected
changes; synced screens reload on app:dataChanged.
This commit is contained in:
Yun Chan 2026-09-27 14:04:49 +09:00
parent b5c9ff9f31
commit 0a4f5aee64
49 changed files with 3940 additions and 1033 deletions

View file

@ -9,6 +9,8 @@ import { getDatabase } from '../db'
import { memoTags, history } from '../db/schema'
import type { MemoTagRow } from '../db/schema'
import { getLogger } from './LoggerService'
import { getCloudSyncService } from './CloudSyncService'
import { memoTagKey, normalizeMemoTag } from './sync/memo-tag-sync'
import { D3ROError, ErrorCode } from '@d3ro/core/errors'
import type {
MemoTag,
@ -43,7 +45,7 @@ class MemoService {
*/
addTag(historyId: string, tag: string): MemoTag {
const db = getDatabase()
const normalizedTag = tag.trim().toLowerCase()
const normalizedTag = normalizeMemoTag(tag)
if (!normalizedTag) {
throw new D3ROError(ErrorCode.ConfigInvalidValue, 'Memo tag is empty')
}
@ -74,6 +76,7 @@ class MemoService {
})
.run()
getCloudSyncService().pushOne('memo_tags', memoTagKey(historyId, normalizedTag))
logger.info(`Tag added: "${normalizedTag}" → history ${historyId}`)
return {
@ -90,7 +93,7 @@ class MemoService {
*/
removeTag(historyId: string, tag: string): void {
const db = getDatabase()
const normalizedTag = tag.trim().toLowerCase()
const normalizedTag = normalizeMemoTag(tag)
const result = db
.delete(memoTags)
@ -104,6 +107,7 @@ class MemoService {
)
}
getCloudSyncService().pushDelete('memo_tags', memoTagKey(historyId, normalizedTag))
logger.info(`Tag removed: "${normalizedTag}" from history ${historyId}`)
}
@ -134,7 +138,7 @@ class MemoService {
searchByTag(params: SearchByTagParams): HistoryPage {
const db = getDatabase()
const { tag, page, pageSize } = params
const normalizedTag = tag.trim().toLowerCase()
const normalizedTag = normalizeMemoTag(tag)
const totalResult = db
.select({ count: count() })
@ -169,7 +173,8 @@ class MemoService {
createdAt: history.createdAt,
updatedAt: history.updatedAt,
appVersion: history.appVersion,
summaryText: history.summaryText
summaryText: history.summaryText,
isFavorite: history.isFavorite
})
.from(memoTags)
.innerJoin(history, eq(memoTags.historyId, history.id))
@ -196,7 +201,7 @@ class MemoService {
// 태그별 히스토리 조회
const tagFilter = params.tag
? eq(memoTags.tag, params.tag.trim().toLowerCase())
? eq(memoTags.tag, normalizeMemoTag(params.tag))
: undefined
const dateConditions: ReturnType<typeof sql>[] = []
@ -333,6 +338,7 @@ class MemoService {
updatedAt: number
appVersion: string
summaryText: string | null
isFavorite: boolean
}): HistoryEntry {
return {
id: row.id,
@ -357,7 +363,8 @@ class MemoService {
createdAt: row.createdAt,
updatedAt: row.updatedAt,
appVersion: row.appVersion,
summaryText: row.summaryText
summaryText: row.summaryText,
isFavorite: row.isFavorite
}
}
}