添加源存在性检查

This commit is contained in:
lyswhut
2022-11-04 15:18:25 +08:00
parent 9e6bfaada4
commit 303d712860
15 changed files with 26 additions and 24 deletions
+1 -1
View File
@@ -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,
+1 -1
View File
@@ -32,7 +32,7 @@ export const listInfos: ListInfos = markRaw({
})
export const maxPages: Partial<Record<LX.OnlineSource, number>> = {}
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<ListInfo>({
page: 1,
+3 -3
View File
@@ -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)
+1 -1
View File
@@ -31,7 +31,7 @@ export const listInfos: ListInfos = markRaw({
})
export const maxPages: Partial<Record<LX.OnlineSource, number>> = {}
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<SearchListInfo>({
page: 1,