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