feat: 渠道选择实装 — v6读取manifest-{channel}.json
- checkUpdate根据选中渠道读取manifest-stable/beta/nightly.json - 三个manifest使用统一H5字段: h5_version/h5_url/h5_sha256 - 版本号比对可独立推进各渠道
This commit is contained in:
@@ -32,35 +32,38 @@ 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 channel='stable';
|
||||
var dlUrl='',dlVer='',dlSha='';
|
||||
var BASE='https://git.childish-ghost.com/LukeMackin/Yuzu-GCA/raw/branch/main/ota';
|
||||
|
||||
function selectCh(el,ch){
|
||||
document.querySelectorAll('.chip').forEach(function(c){c.className='chip chip-off'});
|
||||
el.className='chip chip-on';
|
||||
channel=ch;
|
||||
log('channel: '+ch)
|
||||
}
|
||||
function log(m){document.getElementById('log').innerText+=m+'\n'}
|
||||
function checkUpdate(){
|
||||
fetch(BASE+'/version.txt?t='+Date.now(),{cache:'no-store'})
|
||||
.then(r=>{if(!r.ok)throw Error('HTTP '+r.status);return r.text()})
|
||||
.then(function(t){t=t.trim();log('remote: '+t);
|
||||
var parts=t.split('|');var remoteVer=parts[0];dlUrl=parts[1]||'';dlSha=parts[2]||'';
|
||||
if(!dlUrl)dlUrl=BASE+'/h5/index-v'+remoteVer.replace('0.1.0-dav-android-','')+'.html';
|
||||
if(remoteVer!=='0.1.0-dav-android-6'){dlVer=remoteVer;
|
||||
var manFile='/manifest-'+channel+'.json';
|
||||
log('checking '+manFile+' ...');
|
||||
fetch(BASE+manFile+'?t='+Date.now(),{cache:'no-store'})
|
||||
.then(function(r){if(!r.ok)throw Error('HTTP '+r.status);return r.json()})
|
||||
.then(function(j){log('remote: '+j.h5_version);
|
||||
dlUrl=j.h5_url;dlSha=j.h5_sha256||'';
|
||||
if(!dlUrl){log('ERR: no h5_url');return}
|
||||
if(j.h5_version!=='0.1.0-dav-android-6'){dlVer=j.h5_version;
|
||||
log('*** NEW VERSION ***');document.getElementById('btnApply').disabled=false}
|
||||
else log('up to date')})
|
||||
.catch(function(e){log('ERR: '+e.message)})
|
||||
}
|
||||
function applyUpdate(){
|
||||
fetch(dlUrl+'?t='+Date.now(),{cache:'no-store'})
|
||||
.then(r=>{if(!r.ok)throw Error('HTTP '+r.status);return r.arrayBuffer()})
|
||||
.then(function(buf){
|
||||
return crypto.subtle.digest('SHA-256',buf).then(function(hash){
|
||||
var hex=Array.from(new Uint8Array(hash)).map(function(b){return b.toString(16).padStart(2,'0')}).join('');
|
||||
if(dlSha&&hex!==dlSha){log('SHA256 MISMATCH!');return}
|
||||
Android.saveCache(new TextDecoder().decode(buf));log('OK! restart app to apply')
|
||||
})
|
||||
.then(function(r){if(!r.ok)throw Error('HTTP '+r.status);return r.text()})
|
||||
.then(function(t){
|
||||
if(!dlSha){log('ERR: SHA256 required');return}
|
||||
var h=Android.sha256(t);
|
||||
if(h!==dlSha){log('SHA256 MISMATCH!');return}
|
||||
Android.saveCache(t);log('OK! restart app to apply')
|
||||
})
|
||||
.catch(function(e){log('ERR: '+e.message)})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user