From 303d712860468aab395de7934278d2856640ad8b Mon Sep 17 00:00:00 2001 From: lyswhut Date: Fri, 4 Nov 2022 15:18:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=BA=90=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E6=80=A7=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/components/material/OnlineList/useMenu.js | 2 +- .../components/material/OnlineList/useMusicActions.js | 2 +- src/renderer/store/hotSearch.ts | 10 +++++----- src/renderer/store/leaderboard/action.ts | 4 ++-- src/renderer/store/leaderboard/state.ts | 2 +- src/renderer/store/search/music/action.ts | 2 +- src/renderer/store/search/music/state.ts | 2 +- src/renderer/store/search/songlist/action.ts | 6 +++--- src/renderer/store/search/songlist/state.ts | 2 +- src/renderer/store/songList/action.ts | 2 +- src/renderer/store/songList/state.ts | 2 +- src/renderer/views/Download/useTaskActions.js | 2 +- src/renderer/views/List/MusicList/useMusicActions.js | 2 +- src/renderer/views/List/MyList/index.vue | 2 +- src/renderer/worker/download/utils.ts | 8 +++++--- 15 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/renderer/components/material/OnlineList/useMenu.js b/src/renderer/components/material/OnlineList/useMenu.js index 41d43943..d60d47c8 100644 --- a/src/renderer/components/material/OnlineList/useMenu.js +++ b/src/renderer/components/material/OnlineList/useMenu.js @@ -62,7 +62,7 @@ export default ({ }) const showMenu = (event, musicInfo) => { - itemMenuControl.sourceDetail = !!musicSdk[musicInfo.source].getMusicDetailPageUrl + itemMenuControl.sourceDetail = !!musicSdk[musicInfo.source]?.getMusicDetailPageUrl // this.listMenu.itemMenuControl.play = // this.listMenu.itemMenuControl.playLater = itemMenuControl.download = assertApiSupport(musicInfo.source) diff --git a/src/renderer/components/material/OnlineList/useMusicActions.js b/src/renderer/components/material/OnlineList/useMusicActions.js index 98f9952f..243d5474 100644 --- a/src/renderer/components/material/OnlineList/useMusicActions.js +++ b/src/renderer/components/material/OnlineList/useMusicActions.js @@ -19,7 +19,7 @@ export default ({ props }) => { const handleOpenMusicDetail = index => { const minfo = props.list[index] - const url = musicSdk[minfo.source].getMusicDetailPageUrl(toOldMusicInfo(minfo)) + const url = musicSdk[minfo.source]?.getMusicDetailPageUrl?.(toOldMusicInfo(minfo)) if (!url) return openUrl(url) } diff --git a/src/renderer/store/hotSearch.ts b/src/renderer/store/hotSearch.ts index ccc5b50f..0f26f7a6 100644 --- a/src/renderer/store/hotSearch.ts +++ b/src/renderer/store/hotSearch.ts @@ -17,7 +17,7 @@ export const sourceList: SourceLists = markRaw({ for (const source of music.sources) { - if (!music[source.id as LX.OnlineSource].hotSearch) continue + if (!music[source.id as LX.OnlineSource]?.hotSearch) continue sources.push(source.id as LX.OnlineSource) sourceList[source.id as LX.OnlineSource] = reactive([]) } @@ -52,10 +52,10 @@ export const getList = async(source: Source): Promise => { task.push( sourceList[source]?.length ? Promise.resolve({ source, list: sourceList[source] }) - : music[source].hotSearch.getList().catch((err: any) => { + : music[source]?.hotSearch.getList().catch((err: any) => { console.log(err) return { source, list: [] } - }), + }) ?? Promise.reject(new Error('source not found: ' + source)), ) } return Promise.all(task).then((results: any[]) => { @@ -63,11 +63,11 @@ export const getList = async(source: Source): Promise => { }) } else { if (sourceList[source]?.length) return Promise.resolve(sourceList[source] as string[]) - if (!music[source].hotSearch) { + if (!music[source]?.hotSearch) { setList(source, []) return Promise.resolve([]) } - return music[source].hotSearch.getList().then(data => setList(source, data.list)) + return music[source]?.hotSearch.getList().then(data => setList(source, data.list)) } } diff --git a/src/renderer/store/leaderboard/action.ts b/src/renderer/store/leaderboard/action.ts index d07f9681..fb359fd7 100644 --- a/src/renderer/store/leaderboard/action.ts +++ b/src/renderer/store/leaderboard/action.ts @@ -52,7 +52,7 @@ export const getListDetail = async(id: string, page: number, isRefresh = false): const [source, bangId] = id.split('__') as [LX.OnlineSource, string] - return musicSdk[source]?.leaderboard.getList(bangId, page).then((result: ListDetailInfo) => { + return musicSdk[source]?.leaderboard?.getList(bangId, page).then((result: ListDetailInfo) => { result.list = markRawList(deduplicationList(result.list.map(m => toNewMusicInfo(m)))) cache.set(key, result) return result @@ -78,7 +78,7 @@ export const getListDetailAll = async(id: string, isRefresh = false): Promise toNewMusicInfo(m)))) cache.set(key, result) return result - }) ?? Promise.reject(new Error('source not found')) + }) ?? Promise.reject(new Error('source not found' + source)) } return await loadData(bangId, 1).then((result: ListDetailInfo) => { if (result.total <= result.limit) return result.list diff --git a/src/renderer/store/leaderboard/state.ts b/src/renderer/store/leaderboard/state.ts index 972afda9..de1c458a 100644 --- a/src/renderer/store/leaderboard/state.ts +++ b/src/renderer/store/leaderboard/state.ts @@ -6,7 +6,7 @@ export declare type Source = LX.OnlineSource export const sources: LX.OnlineSource[] = markRaw([]) for (const source of music.sources) { - if (!music[source.id as LX.OnlineSource].leaderboard?.getBoards) continue + if (!music[source.id as LX.OnlineSource]?.leaderboard?.getBoards) continue sources.push(source.id as LX.OnlineSource) } diff --git a/src/renderer/store/search/music/action.ts b/src/renderer/store/search/music/action.ts index 0870ae94..565f1577 100644 --- a/src/renderer/store/search/music/action.ts +++ b/src/renderer/store/search/music/action.ts @@ -90,7 +90,7 @@ export const search = async(text: string, page: number, sourceId: LX.OnlineSourc let task = [] for (const source of sources) { if (source == 'all') continue - task.push(music[source].musicSearch.search(text, page, listInfos.all.limit).catch((error: any) => { + task.push((music[source]?.musicSearch.search(text, page, listInfos.all.limit) ?? Promise.reject(new Error('source not found: ' + source))).catch((error: any) => { console.log(error) return { allPage: 1, diff --git a/src/renderer/store/search/music/state.ts b/src/renderer/store/search/music/state.ts index 37ee60c7..0c08d50f 100644 --- a/src/renderer/store/search/music/state.ts +++ b/src/renderer/store/search/music/state.ts @@ -32,7 +32,7 @@ export const listInfos: ListInfos = markRaw({ }) export const maxPages: Partial> = {} for (const source of music.sources) { - if (!music[source.id as LX.OnlineSource].musicSearch) continue + if (!music[source.id as LX.OnlineSource]?.musicSearch) continue sources.push(source.id as LX.OnlineSource) listInfos[source.id as LX.OnlineSource] = reactive({ page: 1, diff --git a/src/renderer/store/search/songlist/action.ts b/src/renderer/store/search/songlist/action.ts index 1eec7863..c3e2b45a 100644 --- a/src/renderer/store/search/songlist/action.ts +++ b/src/renderer/store/search/songlist/action.ts @@ -91,7 +91,7 @@ export const search = async(text: string, page: number, sourceId: LX.OnlineSourc let task = [] for (const source of sources) { if (source == 'all' || (page > 1 && page > (maxPages[source] as number))) continue - task.push(music[source].songList.search(text, page, listInfos.all.limit).catch((error: any) => { + task.push((music[source]?.songList.search(text, page, listInfos.all.limit) ?? Promise.reject(new Error('source not found: ' + source))).catch((error: any) => { console.log(error) return { list: [], @@ -109,10 +109,10 @@ export const search = async(text: string, page: number, sourceId: LX.OnlineSourc if (listInfo?.key == key && listInfo?.list.length) return listInfo?.list listInfo.noItemLabel = window.i18n.t('list__loading') listInfo.key = key - return music[sourceId].songList.search(text, page, listInfo.limit).then((data: SearchResult) => { + return (music[sourceId]?.songList.search(text, page, listInfo.limit).then((data: SearchResult) => { if (key != listInfo.key) return [] return setList(data, page, text) - }).catch((error: any) => { + }) ?? Promise.reject(new Error('source not found: ' + sourceId))).catch((error: any) => { resetListInfo(sourceId) listInfo.noItemLabel = window.i18n.t('list__load_failed') console.log(error) diff --git a/src/renderer/store/search/songlist/state.ts b/src/renderer/store/search/songlist/state.ts index f9d6fcc0..31062619 100644 --- a/src/renderer/store/search/songlist/state.ts +++ b/src/renderer/store/search/songlist/state.ts @@ -31,7 +31,7 @@ export const listInfos: ListInfos = markRaw({ }) export const maxPages: Partial> = {} for (const source of music.sources) { - if (!music[source.id as LX.OnlineSource].songList?.search) continue + if (!music[source.id as LX.OnlineSource]?.songList?.search) continue sources.push(source.id as LX.OnlineSource) listInfos[source.id as LX.OnlineSource] = reactive({ page: 1, diff --git a/src/renderer/store/songList/action.ts b/src/renderer/store/songList/action.ts index 06c46f97..88800621 100644 --- a/src/renderer/store/songList/action.ts +++ b/src/renderer/store/songList/action.ts @@ -154,7 +154,7 @@ export const getListDetailAll = async(id: string, source: LX.OnlineSource, isRef result.list = markRawList(deduplicationList(result.list.map(m => toNewMusicInfo(m)))) cache.set(key, result) return result - }) ?? Promise.reject(new Error('source not found')) + }) ?? Promise.reject(new Error('source not found' + source)) } return await loadData(id, 1).then((result: ListDetailInfo) => { if (result.total <= result.limit) return result.list diff --git a/src/renderer/store/songList/state.ts b/src/renderer/store/songList/state.ts index 6a395180..9f152d48 100644 --- a/src/renderer/store/songList/state.ts +++ b/src/renderer/store/songList/state.ts @@ -10,7 +10,7 @@ export const sources: LX.OnlineSource[] = markRaw([]) export const sortList = markRaw>>({}) for (const source of music.sources) { - const songList = music[source.id as LX.OnlineSource].songList + const songList = music[source.id as LX.OnlineSource]?.songList if (!songList) continue sources.push(source.id as LX.OnlineSource) sortList[source.id as LX.OnlineSource] = songList.sortList as SortInfo[] diff --git a/src/renderer/views/Download/useTaskActions.js b/src/renderer/views/Download/useTaskActions.js index f0803358..68177ebf 100644 --- a/src/renderer/views/Download/useTaskActions.js +++ b/src/renderer/views/Download/useTaskActions.js @@ -25,7 +25,7 @@ export default ({ list, selectedList, removeAllSelect }) => { const handleOpenMusicDetail = index => { const task = list.value[index] const mInfo = toOldMusicInfo(task.metadata.musicInfo) - const url = musicSdk[mInfo.source].getMusicDetailPageUrl(mInfo) + const url = musicSdk[mInfo.source]?.getMusicDetailPageUrl?.(mInfo) if (!url) return openUrl(url) } diff --git a/src/renderer/views/List/MusicList/useMusicActions.js b/src/renderer/views/List/MusicList/useMusicActions.js index fc2bc3e4..42283ba1 100644 --- a/src/renderer/views/List/MusicList/useMusicActions.js +++ b/src/renderer/views/List/MusicList/useMusicActions.js @@ -24,7 +24,7 @@ export default ({ props, list, selectedList, removeAllSelect }) => { const handleOpenMusicDetail = index => { const minfo = list.value[index] - const url = musicSdk[minfo.source].getMusicDetailPageUrl(toOldMusicInfo(minfo)) + const url = musicSdk[minfo.source]?.getMusicDetailPageUrl(toOldMusicInfo(minfo)) if (!url) return openUrl(url) } diff --git a/src/renderer/views/List/MyList/index.vue b/src/renderer/views/List/MyList/index.vue index 4dee6e85..a1b79d4a 100644 --- a/src/renderer/views/List/MyList/index.vue +++ b/src/renderer/views/List/MyList/index.vue @@ -124,7 +124,7 @@ export default { if (/board__/.test(sourceListId)) { const id = sourceListId.replace(/board__/, '') url = musicSdk[source].leaderboard.getDetailPageUrl(id) - } else if (musicSdk[source].songList?.getDetailPageUrl) { + } else if (musicSdk[source]?.songList?.getDetailPageUrl) { url = await musicSdk[source].songList.getDetailPageUrl(sourceListId) } if (!url) return diff --git a/src/renderer/worker/download/utils.ts b/src/renderer/worker/download/utils.ts index 84622564..f9b16f5e 100644 --- a/src/renderer/worker/download/utils.ts +++ b/src/renderer/worker/download/utils.ts @@ -1,6 +1,6 @@ import { DOWNLOAD_STATUS, QUALITYS } from '@common/constants' import { filterFileName } from '@common/utils/common' -import { joinPath } from '@common/utils/nodejs' +import { joinPath, removeFile } from '@common/utils/nodejs' import fs from 'fs' /** @@ -94,9 +94,11 @@ export const createDownloadInfo = (musicInfo: LX.Music.MusicInfoOnline, type: LX // 删除同路径下的同名文件 // TODO - // deleteFile(downloadInfo.metadata.filePath) + void removeFile(downloadInfo.metadata.filePath) // .catch(err => { - // if (err.code !== 'ENOENT') return commit('setStatusText', { downloadInfo, text: '文件删除失败' }) + // if (err.code !== 'ENOENT') { + // return commit('setStatusText', { downloadInfo, text: '文件删除失败' }) + // } // }) return downloadInfo