导入备份时过滤歌曲
parent
c16de232ad
commit
18b6f73008
|
@ -28,6 +28,14 @@ interface OldUserListInfo {
|
|||
locationUpdateTime?: number
|
||||
list: any[]
|
||||
}
|
||||
const filterMusicList = <T extends LX.Music.MusicInfo>(list: T[]): T[] => {
|
||||
const ids: Set<string> = new Set()
|
||||
return list.filter(s => {
|
||||
if (!s.id || ids.has(s.id)) return false
|
||||
ids.add(s.id)
|
||||
return true
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 迁移 v2.0.0 之前的 list data
|
||||
* @returns
|
||||
|
@ -42,15 +50,15 @@ export const migrateDBData = async() => {
|
|||
}
|
||||
let isRequiredSave = false
|
||||
if (playList) {
|
||||
if (playList.defaultList) listDataAll.defaultList = playList.defaultList.list.map(m => toNewMusicInfo(m))
|
||||
if (playList.loveList) listDataAll.loveList = playList.loveList.list.map(m => toNewMusicInfo(m))
|
||||
if (playList.tempList) listDataAll.tempList = playList.tempList.list.map(m => toNewMusicInfo(m))
|
||||
if (playList.defaultList) listDataAll.defaultList = filterMusicList(playList.defaultList.list.map(m => toNewMusicInfo(m)))
|
||||
if (playList.loveList) listDataAll.loveList = filterMusicList(playList.loveList.list.map(m => toNewMusicInfo(m)))
|
||||
if (playList.tempList) listDataAll.tempList = filterMusicList(playList.tempList.list.map(m => toNewMusicInfo(m)))
|
||||
if (playList.userList) {
|
||||
listDataAll.userList = playList.userList.map(l => {
|
||||
return {
|
||||
...l,
|
||||
locationUpdateTime: l.locationUpdateTime ?? null,
|
||||
list: l.list.map(m => toNewMusicInfo(m)),
|
||||
list: filterMusicList(l.list.map(m => toNewMusicInfo(m))),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -59,8 +67,8 @@ export const migrateDBData = async() => {
|
|||
const config = await parseDataFile<{ list?: { defaultList?: any[], loveList?: any[] } }>('config.json')
|
||||
if (config?.list) {
|
||||
const list = config.list
|
||||
if (list.defaultList) listDataAll.defaultList = list.defaultList.map(m => toNewMusicInfo(m))
|
||||
if (list.loveList) listDataAll.loveList = list.loveList.map(m => toNewMusicInfo(m))
|
||||
if (list.defaultList) listDataAll.defaultList = filterMusicList(list.defaultList.map(m => toNewMusicInfo(m)))
|
||||
if (list.loveList) listDataAll.loveList = filterMusicList(list.loveList.map(m => toNewMusicInfo(m)))
|
||||
isRequiredSave = true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,6 +60,14 @@ export const deduplicationList = <T extends LX.Music.MusicInfo>(list: T[]): T[]
|
|||
return true
|
||||
})
|
||||
}
|
||||
export const filterMusicList = <T extends LX.Music.MusicInfo>(list: T[]): T[] => {
|
||||
const ids: Set<string> = new Set()
|
||||
return list.filter(s => {
|
||||
if (!s.id || ids.has(s.id)) return false
|
||||
ids.add(s.id)
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
export const langS2T = async(str: string) => {
|
||||
return await window.lx.worker.main.langS2t(Buffer.from(str).toString('base64')).then(b64 => Buffer.from(b64, 'base64').toString())
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { toRaw } from '@common/utils/vueTools'
|
||||
import { openSaveDir, showSelectDialog } from '@renderer/utils/ipc'
|
||||
import { useI18n } from '@renderer/plugins/i18n'
|
||||
import { filterFileName, toNewMusicInfo, fixNewMusicInfoQuality } from '@renderer/utils'
|
||||
import { filterFileName, toNewMusicInfo, fixNewMusicInfoQuality, filterMusicList } from '@renderer/utils'
|
||||
import { getListMusics, updateUserList, addListMusics, overwriteListMusics, createUserList } from '@renderer/store/list/action'
|
||||
import { defaultList, loveList, userLists } from '@renderer/store/list/state'
|
||||
import useImportTip from '@renderer/utils/compositions/useImportTip'
|
||||
|
@ -47,7 +47,7 @@ export default () => {
|
|||
switch (configData.type) {
|
||||
case 'playListPart':
|
||||
listData = configData.data
|
||||
listData.list = listData.list.map(m => toNewMusicInfo(m))
|
||||
listData.list = filterMusicList(listData.list.map(m => toNewMusicInfo(m)))
|
||||
break
|
||||
case 'playListPart_v2':
|
||||
listData = configData.data
|
||||
|
|
|
@ -27,6 +27,7 @@ import { toRaw } from '@common/utils/vueTools'
|
|||
import {
|
||||
toNewMusicInfo,
|
||||
// toOldMusicInfo,
|
||||
filterMusicList,
|
||||
fixNewMusicInfoQuality,
|
||||
} from '@renderer/utils'
|
||||
import {
|
||||
|
@ -72,12 +73,12 @@ export default {
|
|||
try {
|
||||
const targetList = allLists.find(l => l.id == list.id)
|
||||
if (targetList) {
|
||||
targetList.list = list.list.map(m => toNewMusicInfo(m))
|
||||
targetList.list = filterMusicList(list.list.map(m => toNewMusicInfo(m)))
|
||||
} else {
|
||||
allLists.push({
|
||||
name: list.name,
|
||||
id: list.id,
|
||||
list: list.list.map(m => toNewMusicInfo(m)),
|
||||
list: filterMusicList(list.list.map(m => toNewMusicInfo(m))),
|
||||
position: list.position,
|
||||
source: list.source,
|
||||
sourceListId: list.sourceListId,
|
||||
|
@ -139,7 +140,7 @@ export default {
|
|||
switch (allData.type) {
|
||||
case 'allData':
|
||||
// 兼容0.6.2及以前版本的列表数据
|
||||
if (allData.defaultList) await overwriteListMusics({ listId: LIST_IDS.DEFAULT, musicInfos: allData.defaultList.list.map(m => toNewMusicInfo(m)) })
|
||||
if (allData.defaultList) await overwriteListMusics({ listId: LIST_IDS.DEFAULT, musicInfos: filterMusicList(allData.defaultList.list.map(m => toNewMusicInfo(m))) })
|
||||
else await importOldListData(allData.playList)
|
||||
importOldSettingData(allData.setting)
|
||||
break
|
||||
|
@ -266,7 +267,7 @@ export default {
|
|||
|
||||
switch (listData.type) {
|
||||
case 'defautlList': // 兼容0.6.2及以前版本的列表数据
|
||||
await overwriteListMusics({ listId: LIST_IDS.DEFAULT, musicInfos: listData.data.list.map(m => toNewMusicInfo(m)) })
|
||||
await overwriteListMusics({ listId: LIST_IDS.DEFAULT, musicInfos: filterMusicList(listData.data.list.map(m => toNewMusicInfo(m))) })
|
||||
break
|
||||
case 'playList':
|
||||
await importOldListData(listData.data)
|
||||
|
|
Loading…
Reference in New Issue