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:
@@ -34,33 +34,30 @@ h1{font-size:20px;color:#fff;margin:0}
|
||||
<button class="btn btn-download" onclick="applyUpdate()" id="btnApply" disabled>下载更新</button>
|
||||
<div class="log" id="log"></div>
|
||||
<script>
|
||||
var dlUrl='',dlVer='',channel='stable';
|
||||
var dlUrl='',dlVer='';
|
||||
var BASE='https://git.childish-ghost.com/LukeMackin/Yuzu-GCA/raw/branch/main/ota';
|
||||
|
||||
function selectCh(ch){
|
||||
channel=ch;
|
||||
var chips=document.querySelectorAll('.chip');
|
||||
for(var i=0;i<chips.length;i++)chips[i].className='chip chip-off';
|
||||
document.querySelectorAll('.chip').forEach(function(c){c.className='chip chip-off'});
|
||||
document.getElementById('ch-'+ch).className='chip chip-on';
|
||||
log('channel: '+ch)
|
||||
}
|
||||
function log(m){document.getElementById('log').innerText+=m+'\n'}
|
||||
function checkUpdate(){
|
||||
var url=BASE+'/version.txt?t='+Date.now();
|
||||
fetch(url,{cache:'no-store'})
|
||||
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]||'';
|
||||
var local='0.1.0-dav-android-6';
|
||||
if(t!==local&&t!=='0.1.0-dav-android-6'){dlVer=t;dlUrl=BASE+'/h5/index-v6.html';
|
||||
if(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...');
|
||||
fetch(dlUrl+'?t='+Date.now(),{cache:'no-store'})
|
||||
.then(r=>{if(!r.ok)throw Error('HTTP '+r.status);return r.text()})
|
||||
.then(function(t){Android.saveCache(t);log('OK! restart app to apply')})
|
||||
.catch(e=>log('ERR: '+e.message))
|
||||
.catch(function(e){log('ERR: '+e.message)})
|
||||
}
|
||||
</script></body></html>
|
||||
|
||||
Reference in New Issue
Block a user