From fc61cf16edad82f643f8f29b1381e6aedb5855cd Mon Sep 17 00:00:00 2001 From: lyswhut Date: Thu, 9 Mar 2023 16:53:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BF=AB=E7=85=A7=E8=A2=AB?= =?UTF-8?q?=E6=84=8F=E5=A4=96=E5=88=A0=E9=99=A4=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/modules/sync/data.ts | 3 ++- src/main/modules/sync/server/syncList.ts | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/modules/sync/data.ts b/src/main/modules/sync/data.ts index 576a9cd5..efc0c120 100644 --- a/src/main/modules/sync/data.ts +++ b/src/main/modules/sync/data.ts @@ -87,7 +87,7 @@ const initDeviceInfo = () => { } const devices = store.get('clients') as DevicesInfo['clients'] | undefined if (devices) devicesInfo.clients = devices - deviceKeys = Object.values(devicesInfo.clients).map(device => device.key).filter(k => k) + deviceKeys = Object.values(devicesInfo.clients).map(device => device.snapshotKey).filter(k => k) const snapshotInfo = store.get('snapshotInfo') as DevicesInfo['snapshotInfo'] | undefined if (snapshotInfo) devicesInfo.snapshotInfo = snapshotInfo } @@ -111,6 +111,7 @@ export const saveClientKeyInfo = (keyInfo: LX.Sync.ServerKeyInfo) => { } export const getClientKeyInfo = (clientId?: string): LX.Sync.ServerKeyInfo | null => { if (!clientId) return null + if (!devicesInfo.serverId) initDeviceInfo() return devicesInfo.clients[clientId] ?? null } export const getServerId = (): string => { diff --git a/src/main/modules/sync/server/syncList.ts b/src/main/modules/sync/server/syncList.ts index 3484e2a4..7e723088 100644 --- a/src/main/modules/sync/server/syncList.ts +++ b/src/main/modules/sync/server/syncList.ts @@ -219,6 +219,10 @@ const overwriteList = (sourceListData: LX.Sync.ListData, targetListData: LX.Sync const handleMergeListData = async(socket: LX.Sync.Server.Socket): Promise<[LX.Sync.ListData, boolean, boolean]> => { const mode: LX.Sync.Mode = await getSyncMode(socket) + if (mode == 'cancel') { + socket.close(SYNC_CLOSE_CODE.normal) + throw new Error('cancel') + } const [remoteListData, localListData] = await Promise.all([getRemoteListData(socket), getLocalListData()]) console.log('handleMergeListData', 'remoteListData, localListData') let listData: LX.Sync.ListData @@ -246,7 +250,7 @@ const handleMergeListData = async(socket: LX.Sync.Server.Socket): Promise<[LX.Sy requiredUpdateRemoteListData = false break // case 'none': return null - case 'cancel': + // case 'cancel': default: socket.close(SYNC_CLOSE_CODE.normal) throw new Error('cancel')