code lint

This commit is contained in:
lyswhut 2023-08-30 14:34:36 +08:00
parent 341bf55c5d
commit 538a140487
20 changed files with 58 additions and 47 deletions

View File

@ -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',

View File

@ -40,7 +40,7 @@ const handleInit = async() => {
})
return
}
isInited = true
isInited ||= true
}
initNavigation(async() => {

View File

@ -57,7 +57,7 @@ export default async() => {
// syncSetting()
isInited = true
isInited ||= true
return handlePushedHomeScreen
}

View File

@ -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<LX.Player.LyricInfo> => {
if (!isRefresh) {
const lyricInfo = await getCachedLyricInfo(musicInfo.metadata.musicInfo)
if (lyricInfo) return await buildLyricInfo(lyricInfo)
if (lyricInfo) return buildLyricInfo(lyricInfo)
}
return getOnlineLyricInfo({

View File

@ -31,11 +31,11 @@ export const getMusicUrl = async({
onToggleSource?: (musicInfo?: LX.Music.MusicInfoOnline) => void
}): Promise<string> => {
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<string> => {
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<LX.Player.LyricInfo> => {
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 })
}
}

View File

@ -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)

View File

@ -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<string> => {
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<LX.Player.LyricInfo> => {
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)
})
}

View File

@ -80,7 +80,7 @@ export const buildLyricInfo = async(lyricInfo: MakeOptional<LX.Player.LyricInfo,
tasks.push(lyricInfo.rlyric ? langS2T(lyricInfo.rlyric) : Promise.resolve(''))
tasks.push(lyricInfo.lxlyric ? langS2T(lyricInfo.lxlyric) : Promise.resolve(''))
}
return await Promise.all(tasks).then(([lyric, tlyric, rlyric, lxlyric, lyric_raw, tlyric_raw, rlyric_raw, lxlyric_raw]) => {
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({

View File

@ -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)

View File

@ -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,

View File

@ -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<number> => {
@ -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<string | null>(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<number | null>(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<typeof DEFAULT_SETTING['
}
export const getSearchHistory = async() => {
// 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<typeof DEFAULT_SETTING
}
export const getLeaderboardSetting = async() => {
// 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<typeof DEFAULT_SETT
}
export const getViewPrevState = async() => {
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之前版本的同步历史

View File

@ -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

View File

@ -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
})
},

View File

@ -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

View File

@ -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

View File

@ -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 {

View File

@ -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

View File

@ -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

View File

@ -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()
}

View File

@ -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) => {