mirror of
https://github.com/ikun0014/lx-music-mobile.git
synced 2025-05-23 22:37:41 +08:00
更新新版本获取地址
This commit is contained in:
parent
d957cd9803
commit
341bf55c5d
16
.github/workflows/publish-version-info.yml
vendored
Normal file
16
.github/workflows/publish-version-info.yml
vendored
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
name: Publish NPM Version Info
|
||||||
|
|
||||||
|
on:
|
||||||
|
release:
|
||||||
|
types: [published]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
dispatch:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Repository Dispatch
|
||||||
|
uses: peter-evans/repository-dispatch@v2
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.PAT }}
|
||||||
|
repository: lyswhut/lx-music-mobile-version-info
|
||||||
|
event-type: npm-release
|
@ -55,6 +55,7 @@ export const storageDataPrefix = {
|
|||||||
searchHistoryList: '@search_history_list',
|
searchHistoryList: '@search_history_list',
|
||||||
listUpdateInfo: '@list_update_info',
|
listUpdateInfo: '@list_update_info',
|
||||||
ignoreVersion: '@ignore_version',
|
ignoreVersion: '@ignore_version',
|
||||||
|
ignoreVersionFailTipTimeKey: '@ignore_version_fail_tip_time',
|
||||||
leaderboardSetting: '@leaderboard_setting',
|
leaderboardSetting: '@leaderboard_setting',
|
||||||
songListSetting: '@songist_setting',
|
songListSetting: '@songist_setting',
|
||||||
searchSetting: '@search_setting',
|
searchSetting: '@search_setting',
|
||||||
|
@ -2,7 +2,7 @@ import { compareVer } from '@/utils'
|
|||||||
import { downloadNewVersion, getVersionInfo } from '@/utils/version'
|
import { downloadNewVersion, getVersionInfo } from '@/utils/version'
|
||||||
import versionActions from '@/store/version/action'
|
import versionActions from '@/store/version/action'
|
||||||
import versionState, { type InitState } from '@/store/version/state'
|
import versionState, { type InitState } from '@/store/version/state'
|
||||||
import { getIgnoreVersion, saveIgnoreVersion } from '@/utils/data'
|
import { getIgnoreVersion, getIgnoreVersionFailTipTime, saveIgnoreVersion, saveIgnoreVersionFailTipTime } from '@/utils/data'
|
||||||
import { showVersionModal } from '@/navigation'
|
import { showVersionModal } from '@/navigation'
|
||||||
import { Navigation } from 'react-native-navigation'
|
import { Navigation } from 'react-native-navigation'
|
||||||
|
|
||||||
@ -40,21 +40,26 @@ export const checkUpdate = async() => {
|
|||||||
// desc: '- 更新xxx\n- 修复xxx123的萨达修复xxx123的萨达修复xxx123的萨达修复xxx123的萨达修复xxx123的萨达',
|
// desc: '- 更新xxx\n- 修复xxx123的萨达修复xxx123的萨达修复xxx123的萨达修复xxx123的萨达修复xxx123的萨达',
|
||||||
// history: [{ version: '1.8.0', desc: '- 更新xxx22\n- 修复xxx22' }, { version: '1.7.0', desc: '- 更新xxx22\n- 修复xxx22' }],
|
// history: [{ version: '1.8.0', desc: '- 更新xxx22\n- 修复xxx22' }, { version: '1.7.0', desc: '- 更新xxx22\n- 修复xxx22' }],
|
||||||
// }
|
// }
|
||||||
if (versionInfo.version == '0.0.0') {
|
if (versionInfo.newVersion.version == '0.0.0') {
|
||||||
versionInfo.isUnknown = true
|
versionInfo.isUnknown = true
|
||||||
versionInfo.status = 'error'
|
versionInfo.status = 'error'
|
||||||
} else {
|
} else {
|
||||||
versionInfo.status = 'idle'
|
versionInfo.status = 'idle'
|
||||||
}
|
|
||||||
versionInfo.isUnknown = false
|
versionInfo.isUnknown = false
|
||||||
if (compareVer(versionInfo.version, versionInfo.newVersion.version) != -1) {
|
if (compareVer(versionInfo.version, versionInfo.newVersion.version) != -1) {
|
||||||
versionInfo.isLatest = true
|
versionInfo.isLatest = true
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
versionActions.setVersionInfo(versionInfo)
|
versionActions.setVersionInfo(versionInfo)
|
||||||
|
|
||||||
if (!versionInfo.isLatest) {
|
if (!versionInfo.isLatest) {
|
||||||
if (versionInfo.newVersion.version != await getIgnoreVersion()) {
|
if (versionInfo.isUnknown) {
|
||||||
|
const time = await getIgnoreVersionFailTipTime()
|
||||||
|
if (Date.now() - time < 7 * 86400000) return
|
||||||
|
saveIgnoreVersionFailTipTime(Date.now())
|
||||||
|
showModal()
|
||||||
|
} else if (versionInfo.newVersion.version != await getIgnoreVersion()) {
|
||||||
showModal()
|
showModal()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ const viewPrevStateKey = storageDataPrefix.viewPrevState
|
|||||||
const listScrollPositionKey = storageDataPrefix.listScrollPosition
|
const listScrollPositionKey = storageDataPrefix.listScrollPosition
|
||||||
const listUpdateInfoKey = storageDataPrefix.listUpdateInfo
|
const listUpdateInfoKey = storageDataPrefix.listUpdateInfo
|
||||||
const ignoreVersionKey = storageDataPrefix.ignoreVersion
|
const ignoreVersionKey = storageDataPrefix.ignoreVersion
|
||||||
|
const ignoreVersionFailTipTimeKey = storageDataPrefix.ignoreVersionFailTipTimeKey
|
||||||
const searchSettingKey = storageDataPrefix.searchSetting
|
const searchSettingKey = storageDataPrefix.searchSetting
|
||||||
const searchHistoryListKey = storageDataPrefix.searchHistoryList
|
const searchHistoryListKey = storageDataPrefix.searchHistoryList
|
||||||
const songListSettingKey = storageDataPrefix.songListSetting
|
const songListSettingKey = storageDataPrefix.songListSetting
|
||||||
@ -172,6 +173,21 @@ export const getIgnoreVersion = async() => {
|
|||||||
return ignoreVersion
|
return ignoreVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let ignoreVersionFailTipTime: number | null
|
||||||
|
export const saveIgnoreVersionFailTipTime = (time: number | null) => {
|
||||||
|
ignoreVersionFailTipTime = time
|
||||||
|
if (time == null) {
|
||||||
|
void removeData(ignoreVersionFailTipTimeKey)
|
||||||
|
} else {
|
||||||
|
void saveData(ignoreVersionFailTipTimeKey, time)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 获取忽略更新的版本号
|
||||||
|
export const getIgnoreVersionFailTipTime = async() => {
|
||||||
|
if (ignoreVersionFailTipTime === undefined) ignoreVersionFailTipTime = (await getData<number | null>(ignoreVersionFailTipTimeKey))
|
||||||
|
return ignoreVersionFailTipTime ?? 0
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export const getSearchSetting = async() => {
|
export const getSearchSetting = async() => {
|
||||||
searchSetting ??= await getData(searchSettingKey) ?? { ...DEFAULT_SETTING.search }
|
searchSetting ??= await getData(searchSettingKey) ?? { ...DEFAULT_SETTING.search }
|
||||||
|
@ -186,6 +186,7 @@ const fetchData = (url, { timeout = 15000, ...options }) => {
|
|||||||
headers: resp.headers.map,
|
headers: resp.headers.map,
|
||||||
body: text,
|
body: text,
|
||||||
statusCode: resp.status,
|
statusCode: resp.status,
|
||||||
|
statusMessage: resp.statusText,
|
||||||
url: resp.url,
|
url: resp.url,
|
||||||
ok: resp.ok,
|
ok: resp.ok,
|
||||||
}
|
}
|
||||||
|
@ -12,49 +12,64 @@ const abis = [
|
|||||||
'universal',
|
'universal',
|
||||||
]
|
]
|
||||||
|
|
||||||
export const getVersionInfo = (retryNum = 0) => {
|
const address = [
|
||||||
return new Promise((resolve, reject) => {
|
[`https://raw.githubusercontent.com/${author.name}/${name}/master/publish/version.json`, 'direct'],
|
||||||
httpGet(`https://raw.githubusercontent.com/${author.name}/${name}/master/publish/version.json`, {
|
['https://registry.npmjs.org/lx-music-mobile-version-info/latest', 'npm'],
|
||||||
timeout: 15000,
|
['https://registry.npmmirror.com/lx-music-mobile-version-info/latest', 'npm'],
|
||||||
|
[`https://cdn.jsdelivr.net/gh/${author.name}/${name}/publish/version.json`, 'direct'],
|
||||||
|
[`https://fastly.jsdelivr.net/gh/${author.name}/${name}/publish/version.json`, 'direct'],
|
||||||
|
[`https://gcore.jsdelivr.net/gh/${author.name}/${name}/publish/version.json`, 'direct'],
|
||||||
|
['https://gitee.com/lyswhut/lx-music-mobile-versions/raw/master/version.json', 'direct'],
|
||||||
|
['http://cdn.stsky.cn/lx-music/mobile/version.json', 'direct'],
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
const request = async(url, retryNum = 0) => {
|
||||||
|
return await new Promise((resolve, reject) => {
|
||||||
|
httpGet(url, {
|
||||||
|
timeout: 10000,
|
||||||
}, (err, resp, body) => {
|
}, (err, resp, body) => {
|
||||||
if (err || body.version == null) {
|
if (err || resp.statusCode != 200) {
|
||||||
// toast(err.message)
|
++retryNum >= 3
|
||||||
return ++retryNum > 1
|
? reject(err || new Error(resp.statusMessage || resp.statusCode))
|
||||||
? getVersionInfo2().then(resolve).catch(reject)
|
: request(url, retryNum).then(resolve).catch(reject)
|
||||||
: getVersionInfo(retryNum).then(resolve).catch(reject)
|
} else resolve(body)
|
||||||
}
|
|
||||||
resolve(body)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const getVersionInfo2 = (retryNum = 0) => {
|
const getDirectInfo = async(url) => {
|
||||||
return new Promise((resolve, reject) => {
|
return request(url).then(info => {
|
||||||
httpGet('https://gitee.com/lyswhut/lx-music-mobile-versions/raw/master/version.json', {
|
if (info.version == null) throw new Error('failed')
|
||||||
timeout: 20000,
|
return info
|
||||||
}, (err, resp, body) => {
|
|
||||||
if (err || body.version == null) {
|
|
||||||
return ++retryNum > 3
|
|
||||||
? getVersionInfo3().then(resolve).catch(reject)
|
|
||||||
: getVersionInfo2(retryNum).then(resolve).catch(reject)
|
|
||||||
}
|
|
||||||
resolve(body)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const getVersionInfo3 = (retryNum = 0) => {
|
const getNpmPkgInfo = async(url) => {
|
||||||
return new Promise((resolve, reject) => {
|
return request(url).then(json => {
|
||||||
httpGet('https://cdn.stsky.cn/lx-music/mobile/version.json', {
|
if (!json.versionInfo) throw new Error('failed')
|
||||||
timeout: 20000,
|
const info = JSON.parse(json.versionInfo)
|
||||||
}, (err, resp, body) => {
|
if (info.version == null) throw new Error('failed')
|
||||||
if (err || body.version == null) {
|
return info
|
||||||
return ++retryNum > 3
|
|
||||||
? resolve({ version: '0.0.0', desc: '', history: [] })
|
|
||||||
: getVersionInfo3(retryNum).then(resolve).catch(reject)
|
|
||||||
}
|
|
||||||
resolve(body)
|
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getVersionInfo = async(index = 0) => {
|
||||||
|
const [url, source] = address[index]
|
||||||
|
let promise
|
||||||
|
switch (source) {
|
||||||
|
case 'direct':
|
||||||
|
promise = getDirectInfo(url)
|
||||||
|
break
|
||||||
|
case 'npm':
|
||||||
|
promise = getNpmPkgInfo(url)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
return promise.catch(async(err) => {
|
||||||
|
index++
|
||||||
|
if (index >= address.length) throw err
|
||||||
|
return getVersionInfo(index)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user