From 74ef112d57bc3c97e6d41990cff6afc4e52fd00e Mon Sep 17 00:00:00 2001 From: lyswhut Date: Sun, 10 Sep 2023 16:10:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=90=8C=E6=AD=A5=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=AD=97=E6=AE=B5=E9=A1=BA=E5=BA=8F=E4=B8=8D=E4=B8=80?= =?UTF-8?q?=E8=87=B4=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/listEvent.ts | 14 +++++++++++++- .../modules/sync/server/modules/list/sync/sync.ts | 8 ++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main/modules/sync/listEvent.ts b/src/main/modules/sync/listEvent.ts index 94c1bd64..d2abd412 100644 --- a/src/main/modules/sync/listEvent.ts +++ b/src/main/modules/sync/listEvent.ts @@ -1,5 +1,17 @@ import { LIST_IDS } from '@common/constants' +// 构建列表信息对象,用于统一字段位置顺序 +export const buildUserListInfoFull = ({ id, name, source, sourceListId, list, locationUpdateTime }: LX.List.UserListInfoFull) => { + return { + id, + name, + source, + sourceListId, + locationUpdateTime, + list, + } +} + export const getLocalListData = async(): Promise => { const lists: LX.Sync.List.ListData = { defaultList: await global.lx.worker.dbService.getListMusics(LIST_IDS.DEFAULT), @@ -10,7 +22,7 @@ export const getLocalListData = async(): Promise => { const userListInfos = await global.lx.worker.dbService.getAllUserList() for await (const list of userListInfos) { lists.userList.push(await global.lx.worker.dbService.getListMusics(list.id) - .then(musics => ({ ...list, list: musics }))) + .then(musics => buildUserListInfoFull({ ...list, list: musics }))) } return lists diff --git a/src/main/modules/sync/server/modules/list/sync/sync.ts b/src/main/modules/sync/server/modules/list/sync/sync.ts index 9994dd01..765e7e23 100644 --- a/src/main/modules/sync/server/modules/list/sync/sync.ts +++ b/src/main/modules/sync/server/modules/list/sync/sync.ts @@ -1,7 +1,7 @@ // import { SYNC_CLOSE_CODE } from '../../../../constants' import { removeSelectModeListener, sendCloseSelectMode, sendSelectMode } from '@main/modules/winMain' import { getUserSpace, getUserConfig } from '../../../user' -import { getLocalListData, setLocalListData } from '@main/modules/sync/listEvent' +import { buildUserListInfoFull, getLocalListData, setLocalListData } from '@main/modules/sync/listEvent' import { SYNC_CLOSE_CODE } from '@common/constants_sync' // import { LIST_IDS } from '@common/constants' @@ -355,14 +355,14 @@ const handleMergeListDataFromSnapshot = async(socket: LX.Sync.Server.Socket, sna let newList: LX.List.UserListInfoFull if (remoteList) { const snapshotList = snapshotUserListData.get(list.id) ?? { name: null, source: null, sourceListId: null, list: [] } - newList = { + newList = buildUserListInfoFull({ id: list.id, - locationUpdateTime: list.locationUpdateTime, name: selectData(snapshotList.name, list.name, remoteList.name), source: selectData(snapshotList.source, list.source, remoteList.source), sourceListId: selectData(snapshotList.sourceListId, list.sourceListId, remoteList.sourceListId), + locationUpdateTime: list.locationUpdateTime, list: mergeListDataFromSnapshot(list.list, remoteList.list, snapshotList.list, addMusicLocationType), - } + }) } else { newList = { ...list } }