mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-05-27 19:20:24 +08:00
⚡ Perf: remove duplicate check of new version, refactor getLatestVersion func
This commit is contained in:
@@ -1,21 +1,23 @@
|
||||
import axios from 'axios'
|
||||
import { RELEASE_URL, RELEASE_URL_BACKUP } from './static'
|
||||
import yaml from 'js-yaml'
|
||||
import { RELEASE_URL, RELEASE_URL_BACKUP } from './static'
|
||||
|
||||
export const getLatestVersion = async () => {
|
||||
let res: string = ''
|
||||
export const getLatestVersion = async (): Promise<string> => {
|
||||
try {
|
||||
res = await axios.get(RELEASE_URL).then(r => {
|
||||
const list = r.data as IStringKeyMap[]
|
||||
const normalList = list.filter(item => !item.name.includes('beta'))
|
||||
return normalList[0].name
|
||||
}).catch(async () => {
|
||||
const result = await axios.get(`${RELEASE_URL_BACKUP}/latest.yml`)
|
||||
const r = yaml.load(result.data) as IStringKeyMap
|
||||
return r.version
|
||||
})
|
||||
const { data } = await axios.get(RELEASE_URL)
|
||||
const releases = data as IStringKeyMap[]
|
||||
const normalList = releases.filter(item => !item.name.includes('beta'))
|
||||
const latestRelease = normalList[0]
|
||||
return latestRelease.name
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
try {
|
||||
const { data } = await axios.get(`${RELEASE_URL_BACKUP}/latest.yml`)
|
||||
const r = yaml.load(data) as IStringKeyMap
|
||||
return r.version
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
return ''
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user