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:
LukeMackin
2026-07-21 19:16:27 +08:00
parent 565b1a5ea1
commit e39a250fbe
3 changed files with 18 additions and 20 deletions

View File

@@ -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>

View File

@@ -1 +1 @@
0.1.0-dav-android-6
0.1.0-dav-android-6|https://git.childish-ghost.com/LukeMackin/Yuzu-GCA/raw/branch/main/ota/h5/index-v6.html

View File

@@ -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>