feat: 渠道选择实装 — v6读取manifest-{channel}.json

- checkUpdate根据选中渠道读取manifest-stable/beta/nightly.json
- 三个manifest使用统一H5字段: h5_version/h5_url/h5_sha256
- 版本号比对可独立推进各渠道
This commit is contained in:
LukeMackin
2026-07-21 21:08:54 +08:00
parent f9d5d32785
commit b4ddb0b5c7
5 changed files with 20 additions and 17 deletions

View File

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

View File

@@ -1 +1 @@
{"version":"0.1.0","builds":{}}
{"h5_version":"0.1.0-dav-android-6","h5_sha256":"6a25c8c5c1e2bacdac416885a0cd4754debf699344d63673cffcc91b5d646295","h5_url":"https://git.childish-ghost.com/LukeMackin/Yuzu-GCA/raw/branch/main/ota/h5/index-v6.html"}

View File

@@ -1 +1 @@
{"version":"0.1.0","builds":{"android":{"type":"apk","tag":"v0.1.0-dav-android-8","url":"https://git.childish-ghost.com/LukeMackin/Yuzu-GCA/releases/download/v0.1.0-dav-android-8/v0.1.0-dav-android-8-debug.apk","sha256":"b2451a398ea2dd34e585c5ec4529d6654451c9b9ab4ddf4a25ec9b032f0ac2bf","size":3506569,"channel":"nightly","minVersion":"0.1.0"}}}
{"h5_version":"0.1.0-dav-android-6","h5_sha256":"6a25c8c5c1e2bacdac416885a0cd4754debf699344d63673cffcc91b5d646295","h5_url":"https://git.childish-ghost.com/LukeMackin/Yuzu-GCA/raw/branch/main/ota/h5/index-v6.html"}

View File

@@ -1 +1 @@
{"version":"0.1.0","builds":{}}
{"h5_version":"0.1.0-dav-android-6","h5_sha256":"6a25c8c5c1e2bacdac416885a0cd4754debf699344d63673cffcc91b5d646295","h5_url":"https://git.childish-ghost.com/LukeMackin/Yuzu-GCA/raw/branch/main/ota/h5/index-v6.html"}

View File

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