fix: 服务器数据纪元保护(空快照不清空本地,自动全量重推自救) / 详情页导出指定日 / 全局计时时钟面板
This commit is contained in:
@@ -300,7 +300,7 @@ export async function runSync(config: SyncConfig): Promise<SyncResult> {
|
||||
}
|
||||
}
|
||||
|
||||
async function doRunSync(config: SyncConfig): Promise<SyncResult> {
|
||||
async function doRunSync(config: SyncConfig, epochRetry = false): Promise<SyncResult> {
|
||||
const base = config.baseUrl.trim().replace(/\/+$/, '')
|
||||
if (!base) throw new Error('请先配置同步服务地址')
|
||||
await ensureSyncFields()
|
||||
@@ -358,6 +358,18 @@ async function doRunSync(config: SyncConfig): Promise<SyncResult> {
|
||||
}
|
||||
if (!resp.ok) throw new Error('同步服务返回 ' + resp.status)
|
||||
const data = await resp.json()
|
||||
|
||||
// 服务器数据纪元检测:纪元变化说明服务端数据存储被重建(如误删 data 目录后重启)。
|
||||
// 此时本地镜像不可信(镜像认为「早已同步」而不推送,随后会拉到空快照把本地缓存清空)。
|
||||
// 处置:作废镜像并以本地全量数据重推一次,让服务器从本设备恢复。
|
||||
const epoch = String(data.dataEpoch || '')
|
||||
const epochKey = 'dsh_sync_epoch_' + (getCloudCreds()?.username || 'anon')
|
||||
const prevEpoch = epoch ? localStorage.getItem(epochKey) : null
|
||||
if (!epochRetry && prevEpoch && epoch && prevEpoch !== epoch) {
|
||||
await db.sync_mirror.clear()
|
||||
localStorage.setItem(epochKey, epoch)
|
||||
return doRunSync(config, true)
|
||||
}
|
||||
const serverTables: Record<string, AnyRow[]> = data.tables || {}
|
||||
const serverTombstones: { table: string; uuid: string; deleted_at: string }[] = data.tombstones || []
|
||||
|
||||
@@ -368,6 +380,7 @@ async function doRunSync(config: SyncConfig): Promise<SyncResult> {
|
||||
ensureSSE(base, getToken() || token)
|
||||
const at = nowLocalISO()
|
||||
await putSyncLastTime(at)
|
||||
if (epoch) localStorage.setItem(epochKey, epoch)
|
||||
if (applyResult.changed > 0 || applyResult.removed > 0 || pushed > 0) notifyAttendanceChanged()
|
||||
return { pushed, pulled: applyResult.changed, removed: applyResult.removed, errors: 0, at }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user