From 538a14048779161a3753123e9b92369253a9d471 Mon Sep 17 00:00:00 2001 From: lyswhut Date: Wed, 30 Aug 2023 14:34:36 +0800 Subject: [PATCH] code lint --- .eslintrc.cjs | 3 +-- src/app.ts | 2 +- src/core/init/index.ts | 2 +- src/core/music/download.ts | 6 +++--- src/core/music/index.ts | 18 +++++++++--------- src/core/music/local.ts | 8 ++++---- src/core/music/online.ts | 12 ++++++------ src/core/music/utils.ts | 8 ++++---- src/core/search/songlist.ts | 2 +- src/theme/themes/index.ts | 1 + src/utils/data.ts | 15 +++++++++++++-- src/utils/musicSdk/kg/lyric.js | 6 +++--- src/utils/musicSdk/kg/pic.js | 4 ++-- src/utils/musicSdk/mg/lyric.js | 6 +++--- src/utils/musicSdk/mg/pic.js | 2 +- src/utils/musicSdk/mg/songList.js | 2 +- src/utils/musicSdk/tx/musicInfo.js | 2 +- src/utils/musicSdk/wy/musicInfo.js | 2 +- src/utils/tools.ts | 2 +- src/utils/version.js | 2 +- 20 files changed, 58 insertions(+), 47 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index ac9c415..75e3505 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -1,4 +1,3 @@ - const baseRule = { 'no-new': 'off', camelcase: 'off', @@ -6,8 +5,8 @@ const baseRule = { 'space-before-function-paren': ['error', 'never'], 'no-var': 'error', 'no-fallthrough': 'off', - 'prefer-promise-reject-errors': 'off', eqeqeq: 'off', + 'require-atomic-updates': ['error', { allowProperties: true }], 'no-multiple-empty-lines': [1, { max: 2 }], 'comma-dangle': [2, 'always-multiline'], 'standard/no-callback-literal': 'off', diff --git a/src/app.ts b/src/app.ts index 409e3b6..9ba31da 100644 --- a/src/app.ts +++ b/src/app.ts @@ -40,7 +40,7 @@ const handleInit = async() => { }) return } - isInited = true + isInited ||= true } initNavigation(async() => { diff --git a/src/core/init/index.ts b/src/core/init/index.ts index 9c3da05..036dba7 100644 --- a/src/core/init/index.ts +++ b/src/core/init/index.ts @@ -57,7 +57,7 @@ export default async() => { // syncSetting() - isInited = true + isInited ||= true return handlePushedHomeScreen } diff --git a/src/core/music/download.ts b/src/core/music/download.ts index 067f78d..0f8923b 100644 --- a/src/core/music/download.ts +++ b/src/core/music/download.ts @@ -18,7 +18,7 @@ export const getMusicUrl = async({ musicInfo, isRefresh, onToggleSource = () => // if (path) return path // } - return await getOnlineMusicUrl({ musicInfo: musicInfo.metadata.musicInfo, isRefresh, onToggleSource }) + return getOnlineMusicUrl({ musicInfo: musicInfo.metadata.musicInfo, isRefresh, onToggleSource }) } export const getPicUrl = async({ musicInfo, isRefresh, listId, onToggleSource = () => {} }: { @@ -38,7 +38,7 @@ export const getPicUrl = async({ musicInfo, isRefresh, listId, onToggleSource = if (onlineMusicInfo.meta.picUrl) return onlineMusicInfo.meta.picUrl } - return await getOnlinePicUrl({ musicInfo: musicInfo.metadata.musicInfo, isRefresh, onToggleSource }).then((url) => { + return getOnlinePicUrl({ musicInfo: musicInfo.metadata.musicInfo, isRefresh, onToggleSource }).then((url) => { // TODO: when listId required save url (update downloadInfo) return url @@ -52,7 +52,7 @@ export const getLyricInfo = async({ musicInfo, isRefresh, onToggleSource = () => }): Promise => { if (!isRefresh) { const lyricInfo = await getCachedLyricInfo(musicInfo.metadata.musicInfo) - if (lyricInfo) return await buildLyricInfo(lyricInfo) + if (lyricInfo) return buildLyricInfo(lyricInfo) } return getOnlineLyricInfo({ diff --git a/src/core/music/index.ts b/src/core/music/index.ts index 45b79b5..a103a12 100644 --- a/src/core/music/index.ts +++ b/src/core/music/index.ts @@ -31,11 +31,11 @@ export const getMusicUrl = async({ onToggleSource?: (musicInfo?: LX.Music.MusicInfoOnline) => void }): Promise => { if ('progress' in musicInfo) { - return await getDownloadMusicUrl({ musicInfo, isRefresh, onToggleSource }) + return getDownloadMusicUrl({ musicInfo, isRefresh, onToggleSource }) } else if (musicInfo.source == 'local') { - return await getLocalMusicUrl({ musicInfo, isRefresh, onToggleSource }) + return getLocalMusicUrl({ musicInfo, isRefresh, onToggleSource }) } else { - return await getOnlineMusicUrl({ musicInfo, isRefresh, quality, onToggleSource }) + return getOnlineMusicUrl({ musicInfo, isRefresh, quality, onToggleSource }) } } @@ -51,11 +51,11 @@ export const getPicPath = async({ onToggleSource?: (musicInfo?: LX.Music.MusicInfoOnline) => void }): Promise => { if ('progress' in musicInfo) { - return await getDownloadPicUrl({ musicInfo, isRefresh, listId, onToggleSource }) + return getDownloadPicUrl({ musicInfo, isRefresh, listId, onToggleSource }) } else if (musicInfo.source == 'local') { - return await getLocalPicUrl({ musicInfo, isRefresh, listId, onToggleSource }) + return getLocalPicUrl({ musicInfo, isRefresh, listId, onToggleSource }) } else { - return await getOnlinePicUrl({ musicInfo, isRefresh, listId, onToggleSource }) + return getOnlinePicUrl({ musicInfo, isRefresh, listId, onToggleSource }) } } @@ -69,10 +69,10 @@ export const getLyricInfo = async({ onToggleSource?: (musicInfo?: LX.Music.MusicInfoOnline) => void }): Promise => { if ('progress' in musicInfo) { - return await getDownloadLyricInfo({ musicInfo, isRefresh, onToggleSource }) + return getDownloadLyricInfo({ musicInfo, isRefresh, onToggleSource }) } else if (musicInfo.source == 'local') { - return await getLocalLyricInfo({ musicInfo, isRefresh, onToggleSource }) + return getLocalLyricInfo({ musicInfo, isRefresh, onToggleSource }) } else { - return await getOnlineLyricInfo({ musicInfo, isRefresh, onToggleSource }) + return getOnlineLyricInfo({ musicInfo, isRefresh, onToggleSource }) } } diff --git a/src/core/music/local.ts b/src/core/music/local.ts index c3af25d..5c6c1f7 100644 --- a/src/core/music/local.ts +++ b/src/core/music/local.ts @@ -23,7 +23,7 @@ export const getMusicUrl = async({ musicInfo, isRefresh, onToggleSource = () => onToggleSource() const otherSource = await getOtherSource(musicInfo) if (!otherSource.length) throw new Error('source not found') - return await getOnlineOtherSourceMusicUrl({ musicInfos: [...otherSource], onToggleSource, isRefresh }).then(({ url, quality: targetQuality, musicInfo: targetMusicInfo, isFromCache }) => { + return getOnlineOtherSourceMusicUrl({ musicInfos: [...otherSource], onToggleSource, isRefresh }).then(({ url, quality: targetQuality, musicInfo: targetMusicInfo, isFromCache }) => { // saveLyric(musicInfo, data.lyricInfo) if (!isFromCache) void saveMusicUrl(targetMusicInfo, targetQuality, url) @@ -48,7 +48,7 @@ export const getPicUrl = async({ musicInfo, listId, isRefresh, onToggleSource = onToggleSource() const otherSource = await getOtherSource(musicInfo) if (!otherSource.length) throw new Error('source not found') - return await getOnlineOtherSourcePicUrl({ musicInfos: [...otherSource], onToggleSource, isRefresh }).then(({ url, musicInfo: targetMusicInfo, isFromCache }) => { + return getOnlineOtherSourcePicUrl({ musicInfos: [...otherSource], onToggleSource, isRefresh }).then(({ url, musicInfo: targetMusicInfo, isFromCache }) => { if (listId) { musicInfo.meta.picUrl = url void updateListMusics([{ id: listId, musicInfo }]) @@ -67,7 +67,7 @@ export const getLyricInfo = async({ musicInfo, isRefresh, onToggleSource = () => const lyricInfo = await getCachedLyricInfo(musicInfo) if (lyricInfo) { // 存在已编辑、原始歌词 - if (lyricInfo.rawlrcInfo.lyric) return await buildLyricInfo(lyricInfo) + if (lyricInfo.rawlrcInfo.lyric) return buildLyricInfo(lyricInfo) } // 尝试读取文件内歌词 @@ -79,7 +79,7 @@ export const getLyricInfo = async({ musicInfo, isRefresh, onToggleSource = () => const otherSource = await getOtherSource(musicInfo) if (!otherSource.length) throw new Error('source not found') // eslint-disable-next-line @typescript-eslint/promise-function-async - return await getOnlineOtherSourceLyricInfo({ musicInfos: [...otherSource], onToggleSource, isRefresh }).then(({ lyricInfo, musicInfo: targetMusicInfo, isFromCache }) => { + return getOnlineOtherSourceLyricInfo({ musicInfos: [...otherSource], onToggleSource, isRefresh }).then(({ lyricInfo, musicInfo: targetMusicInfo, isFromCache }) => { void saveLyric(musicInfo, lyricInfo) if (isFromCache) return buildLyricInfo(lyricInfo) diff --git a/src/core/music/online.ts b/src/core/music/online.ts index 98e5414..26394aa 100644 --- a/src/core/music/online.ts +++ b/src/core/music/online.ts @@ -56,7 +56,7 @@ export const getMusicUrl = async({ musicInfo, quality, isRefresh, allowToggleSou const cachedUrl = await getStoreMusicUrl(musicInfo, targetQuality) if (cachedUrl && !isRefresh) return cachedUrl - return await handleGetOnlineMusicUrl({ musicInfo, quality, onToggleSource, isRefresh, allowToggleSource }).then(({ url, quality: targetQuality, musicInfo: targetMusicInfo, isFromCache }) => { + return handleGetOnlineMusicUrl({ musicInfo, quality, onToggleSource, isRefresh, allowToggleSource }).then(({ url, quality: targetQuality, musicInfo: targetMusicInfo, isFromCache }) => { if (targetMusicInfo.id != musicInfo.id && !isFromCache) void saveMusicUrl(targetMusicInfo, targetQuality, url) void saveMusicUrl(musicInfo, targetQuality, url) return url @@ -71,7 +71,7 @@ export const getPicUrl = async({ musicInfo, listId, isRefresh, allowToggleSource onToggleSource?: (musicInfo?: LX.Music.MusicInfoOnline) => void }): Promise => { if (musicInfo.meta.picUrl && !isRefresh) return musicInfo.meta.picUrl - return await handleGetOnlinePicUrl({ musicInfo, onToggleSource, isRefresh, allowToggleSource }).then(({ url, musicInfo: targetMusicInfo, isFromCache }) => { + return handleGetOnlinePicUrl({ musicInfo, onToggleSource, isRefresh, allowToggleSource }).then(({ url, musicInfo: targetMusicInfo, isFromCache }) => { // picRequest = null if (listId) { musicInfo.meta.picUrl = url @@ -89,16 +89,16 @@ export const getLyricInfo = async({ musicInfo, isRefresh, allowToggleSource = tr }): Promise => { if (!isRefresh) { const lyricInfo = await getCachedLyricInfo(musicInfo) - if (lyricInfo) return await buildLyricInfo(lyricInfo) + if (lyricInfo) return buildLyricInfo(lyricInfo) } // lrcRequest = music[musicInfo.source].getLyric(musicInfo) - return await handleGetOnlineLyricInfo({ musicInfo, onToggleSource, isRefresh, allowToggleSource }).then(async({ lyricInfo, musicInfo: targetMusicInfo, isFromCache }) => { + return handleGetOnlineLyricInfo({ musicInfo, onToggleSource, isRefresh, allowToggleSource }).then(async({ lyricInfo, musicInfo: targetMusicInfo, isFromCache }) => { // lrcRequest = null - if (isFromCache) return await buildLyricInfo(lyricInfo) + if (isFromCache) return buildLyricInfo(lyricInfo) if (targetMusicInfo.id == musicInfo.id) void saveLyric(musicInfo, lyricInfo) else void saveLyric(targetMusicInfo, lyricInfo) - return await buildLyricInfo(lyricInfo) + return buildLyricInfo(lyricInfo) }) } diff --git a/src/core/music/utils.ts b/src/core/music/utils.ts index 31c87b0..268ac84 100644 --- a/src/core/music/utils.ts +++ b/src/core/music/utils.ts @@ -80,7 +80,7 @@ export const buildLyricInfo = async(lyricInfo: MakeOptional { + return Promise.all(tasks).then(([lyric, tlyric, rlyric, lxlyric, lyric_raw, tlyric_raw, rlyric_raw, lxlyric_raw]) => { const rawlrcInfo = lyric_raw ? { lyric: lyric_raw, tlyric: tlyric_raw, @@ -222,7 +222,7 @@ export const handleGetOnlineMusicUrl = async({ musicInfo, quality, onToggleSourc if (!allowToggleSource || err.message == requestMsg.tooManyRequests) throw err onToggleSource() // eslint-disable-next-line @typescript-eslint/promise-function-async - return await getOtherSource(musicInfo).then(otherSource => { + return getOtherSource(musicInfo).then(otherSource => { // console.log('find otherSource', otherSource.length) if (otherSource.length) { return getOnlineOtherSourceMusicUrl({ @@ -306,7 +306,7 @@ export const handleGetOnlinePicUrl = async({ musicInfo, isRefresh, onToggleSourc if (!allowToggleSource) throw err onToggleSource() // eslint-disable-next-line @typescript-eslint/promise-function-async - return await getOtherSource(musicInfo).then(otherSource => { + return getOtherSource(musicInfo).then(otherSource => { // console.log('find otherSource', otherSource.length) if (otherSource.length) { return getOnlineOtherSourcePicUrl({ @@ -403,7 +403,7 @@ export const handleGetOnlineLyricInfo = async({ musicInfo, onToggleSource, isRef onToggleSource() // eslint-disable-next-line @typescript-eslint/promise-function-async - return await getOtherSource(musicInfo).then(otherSource => { + return getOtherSource(musicInfo).then(otherSource => { // console.log('find otherSource', otherSource.length) if (otherSource.length) { return getOnlineOtherSourceLyricInfo({ diff --git a/src/core/search/songlist.ts b/src/core/search/songlist.ts index 00fdb67..ab3af40 100644 --- a/src/core/search/songlist.ts +++ b/src/core/search/songlist.ts @@ -37,7 +37,7 @@ export const search = async(text: string, page: number, sourceId: Source): Promi } })) } - return await Promise.all(task).then((results: SearchResult[]) => { + return Promise.all(task).then((results: SearchResult[]) => { if (key != listInfo.key) return [] setSearchText(text) setSource(sourceId) diff --git a/src/theme/themes/index.ts b/src/theme/themes/index.ts index f8299b4..c8ddede 100644 --- a/src/theme/themes/index.ts +++ b/src/theme/themes/index.ts @@ -18,6 +18,7 @@ export const BG_IMAGES = { let userThemes: LX.Theme[] export const getAllThemes = async() => { + // eslint-disable-next-line require-atomic-updates userThemes ??= await getUserTheme() return { themes, diff --git a/src/utils/data.ts b/src/utils/data.ts index 8093eb1..cdd1469 100644 --- a/src/utils/data.ts +++ b/src/utils/data.ts @@ -69,6 +69,7 @@ export const saveUserTheme = async(themes: LX.Theme[]) => { const initPosition = async() => { + // eslint-disable-next-line require-atomic-updates listPosition ??= await getData(listScrollPositionKey) ?? {} } export const getListPosition = async(id: string): Promise => { @@ -100,6 +101,7 @@ const saveListPrevSelectIdThrottle = throttle(() => { void saveData(listPrevSelectIdKey, listPrevSelectId) }, 200) export const getListPrevSelectId = async() => { + // eslint-disable-next-line require-atomic-updates listPrevSelectId ??= await getData(listPrevSelectIdKey) ?? LIST_IDS.DEFAULT return listPrevSelectId || LIST_IDS.DEFAULT } @@ -113,6 +115,7 @@ const saveListUpdateInfoThrottle = throttle(() => { }, 1000) const initListUpdateInfo = async() => { + // eslint-disable-next-line require-atomic-updates listUpdateInfo ??= await getData(listUpdateInfoKey) ?? {} } export const getListUpdateInfo = async() => { @@ -169,6 +172,7 @@ export const saveIgnoreVersion = (version: string | null) => { } // 获取忽略更新的版本号 export const getIgnoreVersion = async() => { + // eslint-disable-next-line require-atomic-updates if (ignoreVersion === undefined) ignoreVersion = (await getData(ignoreVersionKey)) ?? null return ignoreVersion } @@ -184,12 +188,14 @@ export const saveIgnoreVersionFailTipTime = (time: number | null) => { } // 获取忽略更新的版本号 export const getIgnoreVersionFailTipTime = async() => { + // eslint-disable-next-line require-atomic-updates if (ignoreVersionFailTipTime === undefined) ignoreVersionFailTipTime = (await getData(ignoreVersionFailTipTimeKey)) return ignoreVersionFailTipTime ?? 0 } export const getSearchSetting = async() => { + // eslint-disable-next-line require-atomic-updates searchSetting ??= await getData(searchSettingKey) ?? { ...DEFAULT_SETTING.search } return { ...searchSetting } } @@ -206,16 +212,18 @@ export const saveSearchSetting = async(setting: Partial { + // eslint-disable-next-line require-atomic-updates searchHistoryList ??= await getData(searchHistoryListKey) ?? [] return [...searchHistoryList] } export const saveSearchHistory = async(historyList: typeof searchHistoryList) => { - if (!searchHistoryList) await getSearchHistory() + // if (!searchHistoryList) await getSearchHistory() searchHistoryList = historyList saveSearchHistoryThrottle() } export const getSongListSetting = async() => { + // eslint-disable-next-line require-atomic-updates songListSetting ??= await getData(songListSettingKey) ?? { ...DEFAULT_SETTING.songList } return { ...songListSetting } } @@ -226,6 +234,7 @@ export const saveSongListSetting = async(setting: Partial { + // eslint-disable-next-line require-atomic-updates leaderboardSetting ??= await getData(leaderboardSettingKey) ?? { ...DEFAULT_SETTING.leaderboard } return { ...leaderboardSetting } } @@ -236,7 +245,7 @@ export const saveLeaderboardSetting = async(setting: Partial { - return await getData<{ id: NAV_ID_Type }>(viewPrevStateKey) ?? { ...DEFAULT_SETTING.viewPrevState } + return (await getData<{ id: NAV_ID_Type }>(viewPrevStateKey)) ?? { ...DEFAULT_SETTING.viewPrevState } } export const saveViewPrevState = (state: { id: NAV_ID_Type }) => { saveViewPrevStateThrottle(state) @@ -397,6 +406,7 @@ export const setSyncAuthKey = async(serverId: string, info: LX.Sync.KeyInfo) => let syncHostInfo: string export const getSyncHost = async() => { if (syncHostInfo === undefined) { + // eslint-disable-next-line require-atomic-updates syncHostInfo = await getData(syncHostPrefix) ?? '' // 清空1.0.0之前版本的同步主机 @@ -414,6 +424,7 @@ export const setSyncHost = async(host: string) => { let syncHostHistory: string[] export const getSyncHostHistory = async() => { if (syncHostHistory === undefined) { + // eslint-disable-next-line require-atomic-updates syncHostHistory = await getData(syncHostHistoryPrefix) ?? [] // 清空1.0.0之前版本的同步历史 diff --git a/src/utils/musicSdk/kg/lyric.js b/src/utils/musicSdk/kg/lyric.js index 3e16e2a..ab6d341 100644 --- a/src/utils/musicSdk/kg/lyric.js +++ b/src/utils/musicSdk/kg/lyric.js @@ -76,7 +76,7 @@ export default { // }) // requestObj.promise = requestObj.promise.then(({ body, statusCode }) => { // if (statusCode !== 200) { - // if (tryNum > 5) return Promise.reject('歌词获取失败') + // if (tryNum > 5) return Promise.reject(new Error('歌词获取失败')) // let tryRequestObj = this.getLyric(songInfo, ++tryNum) // requestObj.cancelHttp = tryRequestObj.cancelHttp.bind(tryRequestObj) // return tryRequestObj.promise @@ -98,7 +98,7 @@ export default { }) requestObj.promise = requestObj.promise.then(({ body, statusCode }) => { if (statusCode !== 200) { - if (tryNum > 5) return Promise.reject('歌词获取失败') + if (tryNum > 5) return Promise.reject(new Error('歌词获取失败')) let tryRequestObj = this.searchLyric(name, hash, time, ++tryNum) requestObj.cancelHttp = tryRequestObj.cancelHttp.bind(tryRequestObj) return tryRequestObj.promise @@ -121,7 +121,7 @@ export default { }) requestObj.promise = requestObj.promise.then(({ body, statusCode }) => { if (statusCode !== 200) { - if (tryNum > 5) return Promise.reject('歌词获取失败') + if (tryNum > 5) return Promise.reject(new Error('歌词获取失败')) let tryRequestObj = this.getLyric(id, accessKey, ++tryNum) requestObj.cancelHttp = tryRequestObj.cancelHttp.bind(tryRequestObj) return tryRequestObj.promise diff --git a/src/utils/musicSdk/kg/pic.js b/src/utils/musicSdk/kg/pic.js index fdb4017..9b28b93 100644 --- a/src/utils/musicSdk/kg/pic.js +++ b/src/utils/musicSdk/kg/pic.js @@ -38,10 +38,10 @@ export default { }, ) return requestObj.promise.then(({ body }) => { - if (body.error_code !== 0) return Promise.reject('图片获取失败') + if (body.error_code !== 0) return Promise.reject(new Error('图片获取失败')) let info = body.data[0].info const img = info.imgsize ? info.image.replace('{size}', info.imgsize[0]) : info.image - if (!img) return Promise.reject('Pic get failed') + if (!img) return Promise.reject(new Error('Pic get failed')) return img }) }, diff --git a/src/utils/musicSdk/mg/lyric.js b/src/utils/musicSdk/mg/lyric.js index 8511cdb..7500f14 100644 --- a/src/utils/musicSdk/mg/lyric.js +++ b/src/utils/musicSdk/mg/lyric.js @@ -57,7 +57,7 @@ const mrcTools = { }) return requestObj.promise.then(({ statusCode, body }) => { if (statusCode == 200) return body - if (tryNum > 5 || statusCode == 404) return Promise.reject('歌词获取失败') + if (tryNum > 5 || statusCode == 404) return Promise.reject(new Error('歌词获取失败')) return this.getText(url, ++tryNum) }) }, @@ -84,7 +84,7 @@ const mrcTools = { let p if (info.mrcUrl) p = this.getMrc(info.mrcUrl) else if (info.lrcUrl) p = this.getLrc(info.lrcUrl) - if (p == null) return Promise.reject('获取歌词失败') + if (p == null) return Promise.reject(new Error('获取歌词失败')) return Promise.all([p, this.getTrc(info.trcUrl)]).then(([lrcInfo, tlyric]) => { lrcInfo.tlyric = tlyric return lrcInfo @@ -102,7 +102,7 @@ export default { let requestObj = httpFetch(songInfo.lrcUrl) requestObj.promise = requestObj.promise.then(({ body, statusCode }) => { if (statusCode !== 200) { - if (tryNum > 5) return Promise.reject('歌词获取失败') + if (tryNum > 5) return Promise.reject(new Error('歌词获取失败')) let tryRequestObj = this.getLyricWeb(songInfo, ++tryNum) requestObj.cancelHttp = tryRequestObj.cancelHttp.bind(tryRequestObj) return tryRequestObj.promise diff --git a/src/utils/musicSdk/mg/pic.js b/src/utils/musicSdk/mg/pic.js index 046eba0..cf819ca 100644 --- a/src/utils/musicSdk/mg/pic.js +++ b/src/utils/musicSdk/mg/pic.js @@ -10,7 +10,7 @@ export default { }) requestObj.promise.then(({ body }) => { if (body.returnCode !== '000000') { - if (tryNum > 5) return Promise.reject('图片获取失败') + if (tryNum > 5) return Promise.reject(new Error('图片获取失败')) let tryRequestObj = this.getPic(songId, ++tryNum) requestObj.cancelHttp = tryRequestObj.cancelHttp.bind(tryRequestObj) return tryRequestObj.promise diff --git a/src/utils/musicSdk/mg/songList.js b/src/utils/musicSdk/mg/songList.js index 8560de4..8f11bad 100644 --- a/src/utils/musicSdk/mg/songList.js +++ b/src/utils/musicSdk/mg/songList.js @@ -170,7 +170,7 @@ export default { // return this._requestObj_list.promise.then(({ statusCode, body }) => { // if (statusCode !== 200) return this.getList(sortId, tagId, page) // let list = body.replace(/[\r\n]/g, '').match(this.regExps.list) - // if (!list) return Promise.reject('获取列表失败') + // if (!list) return Promise.reject(new Error('获取列表失败')) // return list.map(item => { // let info = item.match(this.regExps.listInfo) // return { diff --git a/src/utils/musicSdk/tx/musicInfo.js b/src/utils/musicSdk/tx/musicInfo.js index 970b8f6..b490a3c 100644 --- a/src/utils/musicSdk/tx/musicInfo.js +++ b/src/utils/musicSdk/tx/musicInfo.js @@ -33,7 +33,7 @@ export default (songmid) => { }) return requestObj.promise.then(({ body }) => { // console.log(body) - if (body.code != 0 || body.req.code != 0) return Promise.reject('获取歌曲信息失败') + if (body.code != 0 || body.req.code != 0) return Promise.reject(new Error('获取歌曲信息失败')) const item = body.req.data.track_info if (!item.file?.media_mid) return null diff --git a/src/utils/musicSdk/wy/musicInfo.js b/src/utils/musicSdk/wy/musicInfo.js index 88a5da5..b9ff094 100644 --- a/src/utils/musicSdk/wy/musicInfo.js +++ b/src/utils/musicSdk/wy/musicInfo.js @@ -17,7 +17,7 @@ export default songmid => { }) requestObj.promise = requestObj.promise.then(({ body }) => { // console.log(body) - if (body.code !== 200 || !body.songs.length) return Promise.reject('获取歌曲信息失败') + if (body.code !== 200 || !body.songs.length) return Promise.reject(new Error('获取歌曲信息失败')) return body.songs[0] }) return requestObj diff --git a/src/utils/tools.ts b/src/utils/tools.ts index 189aba3..b4265a1 100644 --- a/src/utils/tools.ts +++ b/src/utils/tools.ts @@ -19,7 +19,7 @@ export const getDeviceLanguage = async() => { // NativeModules.SettingsManager.settings.AppleLanguages[0] // iOS 13 // : await getSystemLocales() // deviceLanguage = typeof deviceLanguage === 'string' ? deviceLanguage.substring(0, 5).toLocaleLowerCase() : '' - return await getSystemLocales() + return getSystemLocales() } diff --git a/src/utils/version.js b/src/utils/version.js index e9f3146..22fe17d 100644 --- a/src/utils/version.js +++ b/src/utils/version.js @@ -25,7 +25,7 @@ const address = [ const request = async(url, retryNum = 0) => { - return await new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { httpGet(url, { timeout: 10000, }, (err, resp, body) => {