mirror of
https://github.com/qier222/YesPlayMusic.git
synced 2024-11-22 12:47:27 +08:00
fix: retry when personalFM not found data (#1231)
* fix: retry when personalFM not found data * fix * fix: retry count
This commit is contained in:
parent
d716bb8cde
commit
75fed70c38
|
@ -15,6 +15,12 @@ const electron =
|
|||
process.env.IS_ELECTRON === true ? window.require('electron') : null;
|
||||
const ipcRenderer =
|
||||
process.env.IS_ELECTRON === true ? electron.ipcRenderer : null;
|
||||
const delay = ms =>
|
||||
new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
resolve('');
|
||||
}, ms);
|
||||
});
|
||||
const excludeSaveKeys = [
|
||||
'_playing',
|
||||
'_personalFMLoading',
|
||||
|
@ -577,12 +583,29 @@ export default class {
|
|||
this._isPersonalFM = true;
|
||||
if (!this._personalFMNextTrack) {
|
||||
this._personalFMLoading = true;
|
||||
let result = await personalFM().catch(() => null);
|
||||
let result = null;
|
||||
let retryCount = 5;
|
||||
for (; retryCount >= 0; retryCount--) {
|
||||
result = await personalFM().catch(() => null);
|
||||
if (!result) {
|
||||
this._personalFMLoading = false;
|
||||
if (!result || !result.data) {
|
||||
store.dispatch('showToast', 'personal fm timeout');
|
||||
return false;
|
||||
}
|
||||
if (result.data?.length > 0) {
|
||||
break;
|
||||
} else if (retryCount > 0) {
|
||||
await delay(1000);
|
||||
}
|
||||
}
|
||||
this._personalFMLoading = false;
|
||||
|
||||
if (retryCount < 0) {
|
||||
let content = '获取私人FM数据时重试次数过多,请手动切换下一首';
|
||||
store.dispatch('showToast', content);
|
||||
console.log(content);
|
||||
return false;
|
||||
}
|
||||
// 这里只能拿到一条数据
|
||||
this._personalFMTrack = result.data[0];
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue
Block a user