优化
This commit is contained in:
+9
-2
@@ -30,10 +30,11 @@ function getRuntimeInfo() {
|
||||
})
|
||||
}
|
||||
|
||||
function normalizeUpdate(payload) {
|
||||
function normalizeUpdate(payload, runtime) {
|
||||
const value = payload && typeof payload === 'object' ? payload : {}
|
||||
if (value.update !== true) return null
|
||||
|
||||
if (value.appid !== runtime.appid) throw new Error('更新包与当前应用不匹配')
|
||||
const packageType = String(value.packageType || '').toLowerCase()
|
||||
const downloadUrl = String(value.downloadUrl || '').trim()
|
||||
const versionName = String(value.versionName || '').trim()
|
||||
@@ -41,12 +42,18 @@ function normalizeUpdate(payload) {
|
||||
throw new Error('更新服务返回了无效的版本信息')
|
||||
}
|
||||
if (!/^https:\/\//i.test(downloadUrl)) throw new Error('更新包必须使用 HTTPS 地址')
|
||||
const minAppVersionCode = Number(value.minAppVersionCode)
|
||||
if (packageType === 'wgt' && (!Number.isInteger(minAppVersionCode) || minAppVersionCode < 1
|
||||
|| minAppVersionCode > runtime.appVersionCode)) {
|
||||
throw new Error('当前安装包不支持此热更新,请安装新版 APK')
|
||||
}
|
||||
|
||||
return {
|
||||
packageType,
|
||||
downloadUrl,
|
||||
versionName,
|
||||
versionCode: Number(value.versionCode || 0),
|
||||
minAppVersionCode,
|
||||
mandatory: value.mandatory === true,
|
||||
releaseNotes: String(value.releaseNotes || '').trim()
|
||||
}
|
||||
@@ -181,7 +188,7 @@ export async function checkForAppUpdate({ manual = false } = {}) {
|
||||
})
|
||||
if (response.statusCode !== 200) throw new Error('更新服务暂时不可用')
|
||||
|
||||
const update = normalizeUpdate(response.data?.data ?? response.data)
|
||||
const update = normalizeUpdate(response.data?.data ?? response.data, runtime)
|
||||
if (update && isNewerUpdate(update, runtime)) {
|
||||
await runUpdate(update)
|
||||
} else if (manual) {
|
||||
|
||||
Reference in New Issue
Block a user