fix: version.txt格式改为version|url — 消除所有硬编码dlUrl
- version.txt: 0.1.0-dav-android-6|完整下载URL - index.html: 动态解析|分隔符获取下载路径 - index-v6.html: 同逻辑,不硬编码 - 以后升级只需改version.txt指向新文件
This commit is contained in:
@@ -23,19 +23,20 @@ function checkUpdate(){
|
||||
log('checking...');
|
||||
fetch(BASE+'/version.txt?t='+Date.now(),{cache:'no-store'})
|
||||
.then(r=>{if(!r.ok)throw Error('HTTP '+r.status);return r.text()})
|
||||
.then(t=>{t=t.trim();log('remote: '+t);
|
||||
.then(function(t){t=t.trim();log('remote: '+t);
|
||||
var parts=t.indexOf('|')>0?t.split('|'):[t];var remoteVer=parts[0];dlUrl=parts[1]||'';
|
||||
if(!dlUrl)dlUrl=BASE+'/h5/index-v'+remoteVer.replace('0.1.0-dav-android-','')+'.html';
|
||||
var local=document.getElementById('ver').innerText;
|
||||
if(t!==local&&t!=='v'+local&&'v'+t!==local){dlVer=t;dlUrl=BASE+'/h5/index-v6.html';
|
||||
log('*** NEW VERSION ***');document.getElementById('btnApply').disabled=false}
|
||||
if(remoteVer!==local&&remoteVer!=='v'+local&&'v'+remoteVer!==local){
|
||||
dlVer=remoteVer;log('*** NEW VERSION ***');document.getElementById('btnApply').disabled=false}
|
||||
else log('up to date')})
|
||||
.catch(e=>log('ERR: '+e.message))
|
||||
.catch(function(e){log('ERR: '+e.message)})
|
||||
}
|
||||
function applyUpdate(){
|
||||
log('downloading...');
|
||||
log('downloading: '+dlUrl+' ...');
|
||||
fetch(dlUrl+'?t='+Date.now(),{cache:'no-store'})
|
||||
.then(r=>{if(!r.ok)throw Error('HTTP '+r.status);return r.text()})
|
||||
.then(t=>{Android.saveCache(t);log('OK! restart app to apply');
|
||||
document.getElementById('btnApply').disabled=true})
|
||||
.catch(e=>log('ERR: '+e.message))
|
||||
.then(function(t){Android.saveCache(t);log('OK! restart app to apply')})
|
||||
.catch(function(e){log('ERR: '+e.message)})
|
||||
}
|
||||
</script></body></html>
|
||||
|
||||
Reference in New Issue
Block a user