🐛 Fix: releaseUrl may can't get latest version

This commit is contained in:
Molunerfinn 2020-01-09 12:09:54 +08:00
parent 3caeccc492
commit ee46ab1fb7
2 changed files with 17 additions and 7 deletions

View File

@ -3,7 +3,8 @@ import db from '#/datastore'
import axios from 'axios'
import pkg from 'root/package.json'
const version = pkg.version
let release = 'https://cdn.jsdelivr.net/gh/Molunerfinn/PicGo/package.json'
const releaseUrl = 'https://api.github.com/repos/Molunerfinn/PicGo/releases/latest'
const releaseUrlBackup = 'https://cdn.jsdelivr.net/gh/Molunerfinn/PicGo@latest/package.json'
const downloadUrl = 'https://github.com/Molunerfinn/PicGo/releases/latest'
const checkVersion = async () => {
@ -15,12 +16,15 @@ const checkVersion = async () => {
if (showTip) {
let res: any
try {
res = await axios.get(release)
res = await axios.get(releaseUrl).catch(async () => {
const result = await axios.get(releaseUrlBackup)
return result
})
} catch (err) {
console.log(err)
}
if (res.status === 200) {
const latest = res.data.version
const latest = res.data.version || res.data.name
const result = compareVersion2Update(version, latest)
if (result) {
dialog.showMessageBox({

View File

@ -305,7 +305,8 @@ import {
} from 'electron'
import { Component, Vue } from 'vue-property-decorator'
import db from '#/datastore'
const release = 'https://api.github.com/repos/Molunerfinn/PicGo/releases/latest'
const releaseUrl = 'https://api.github.com/repos/Molunerfinn/PicGo/releases/latest'
const releaseUrlBackup = 'https://cdn.jsdelivr.net/gh/Molunerfinn/PicGo@latest/package.json'
const downloadUrl = 'https://github.com/Molunerfinn/PicGo/releases/latest'
const customLinkRule = (rule: string, value: string, callback: (arg0?: Error) => void) => {
if (!/\$url/.test(value)) {
@ -484,11 +485,16 @@ export default class extends Vue {
}
checkUpdate () {
this.checkUpdateVisible = true
this.$http.get(release)
this.$http.get(releaseUrl)
.then(res => {
this.latestVersion = res.data.name
}).catch(err => {
console.log(err)
}).catch(async () => {
this.$http.get(releaseUrlBackup)
.then(res => {
this.latestVersion = res.data.version
}).catch(() => {
this.latestVersion = '网络错误暂时无法获取'
})
})
}
confirmCheckVersion () {