-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚡ Perf: remove duplicate check of new version, refactor getLatestVers…
…ion func
- Loading branch information
1 parent
15d34ac
commit ef917ce
Showing
2 changed files
with
18 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |