Skip to content

Commit

Permalink
code lint
Browse files Browse the repository at this point in the history
  • Loading branch information
lyswhut committed Aug 30, 2023
1 parent 341bf55 commit 538a140
Show file tree
Hide file tree
Showing 20 changed files with 58 additions and 47 deletions.
3 changes: 1 addition & 2 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@

const baseRule = {
'no-new': 'off',
camelcase: 'off',
'no-return-assign': 'off',
'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',
Expand Down
2 changes: 1 addition & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const handleInit = async() => {
})
return
}
isInited = true
isInited ||= true
}

initNavigation(async() => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/init/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default async() => {

// syncSetting()

isInited = true
isInited ||= true

return handlePushedHomeScreen
}
6 changes: 3 additions & 3 deletions src/core/music/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {} }: {
Expand All @@ -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
Expand All @@ -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({
Expand Down
18 changes: 9 additions & 9 deletions src/core/music/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
}

Expand All @@ -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 })
}
}

Expand All @@ -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 })
}
}
8 changes: 4 additions & 4 deletions src/core/music/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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 }])
Expand All @@ -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)
}

// 尝试读取文件内歌词
Expand All @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions src/core/music/online.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
})
}
8 changes: 4 additions & 4 deletions src/core/music/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion src/core/search/songlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/theme/themes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 13 additions & 2 deletions src/utils/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> => {
Expand Down Expand Up @@ -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
}
Expand All @@ -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() => {
Expand Down Expand Up @@ -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
}
Expand All @@ -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 }
}
Expand All @@ -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 }
}
Expand All @@ -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 }
}
Expand All @@ -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)
Expand Down Expand Up @@ -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之前版本的同步主机
Expand All @@ -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之前版本的同步历史
Expand Down
6 changes: 3 additions & 3 deletions src/utils/musicSdk/kg/lyric.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/utils/musicSdk/kg/pic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
},
Expand Down
6 changes: 3 additions & 3 deletions src/utils/musicSdk/mg/lyric.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
},
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit 538a140

Please sign in to comment.