no message

This commit is contained in:
2026-06-18 13:58:39 +08:00
parent 33070ad827
commit b08562d603
4936 changed files with 1887 additions and 21 deletions

View File

@@ -20,36 +20,59 @@ export function getUnityCdnBuildRoot() {
return `${getUnityCdnRoot()}/Build`;
}
/** 预取关卡库并注入,避免 LevelDatabase 回退到 /unity/ 或 editor 相对路径 */
export async function prefetchLevelsDatabase(cdnRoot) {
const root = String(cdnRoot || getUnityCdnRoot()).replace(/\/$/, '');
const jsonUrl = `${root}/levels-database.json`;
window.__tfrhLevelsDatabaseUrl = jsonUrl;
if (window.__tfrhLevelsDatabaseJson) {
return;
}
async function fetchJsonWithBrotli(jsonUrl) {
const brUrl = jsonUrl.replace(/\.json(\?.*)?$/i, '.json.br$1');
if (typeof DecompressionStream !== 'undefined') {
try {
const brRes = await fetch(brUrl);
if (brRes.ok) {
const text = await new Response(await brRes.arrayBuffer())
.pipeThrough(new DecompressionStream('brotli'))
.text();
window.__tfrhLevelsDatabaseJson = JSON.parse(text);
return;
const ab = await brRes.arrayBuffer();
let text = new TextDecoder().decode(ab);
if (text.charCodeAt(0) !== 0x7b && text.charCodeAt(0) !== 0x5b) {
text = await new Response(ab)
.pipeThrough(new DecompressionStream('brotli'))
.text();
}
return JSON.parse(text);
}
} catch (e) {
console.warn('[unity-cdn] levels-database.json.br 预取失败,尝试 .json', e);
console.warn('[unity-cdn] Brotli 预取失败,尝试 .json', jsonUrl, e);
}
}
const res = await fetch(jsonUrl);
if (!res.ok) {
throw new Error(`levels-database HTTP ${res.status}: ${jsonUrl}`);
throw new Error(`HTTP ${res.status}: ${jsonUrl}`);
}
window.__tfrhLevelsDatabaseJson = await res.json();
return res.json();
}
/** 首屏只预取关卡库索引分片模式legacy 全量库作回退 URL */
export async function prefetchLevelsDatabase(cdnRoot) {
const root = String(cdnRoot || getUnityCdnRoot()).replace(/\/$/, '');
const indexUrl = `${root}/levels-db-index.json`;
const jsonUrl = `${root}/levels-database.json`;
window.__tfrhLevelsDbIndexUrl = indexUrl;
window.__tfrhLevelsDatabaseUrl = jsonUrl;
if (window.__tfrhLevelsDbIndex) {
return;
}
try {
const index = await fetchJsonWithBrotli(indexUrl);
if (index?.mode === 'sharded' && index.shards?.length) {
window.__tfrhLevelsDbIndex = index;
return;
}
} catch (e) {
console.warn('[unity-cdn] levels-db-index 预取失败,启动时将回退全量库', e);
}
if (window.__tfrhLevelsDatabaseJson) {
return;
}
window.__tfrhLevelsDatabaseJson = await fetchJsonWithBrotli(jsonUrl);
}

View File

@@ -167,15 +167,15 @@ const CONFIG = {
version: "20260520",
/** OSS 真实地址(生产环境浏览器直连) */
unityCdnRemote: 'https://oss.eanic.cn/001_code_cocos_res_20260616',
unityCdnRemote: 'https://oss.eanic.cn/001_code_cocos_res_20260617',
/** 方案 Bnginx / webpack 同源代理前缀(方案 A 直连 OSS 请保持 false */
unityCdnDevProxy: '/cdn-unity',
/** 本地 npm start 也走代理(仅 unityCdnUseSiteProxy 或此项为 true 时生效) */
unityCdnUseDevProxy: false,
/** 生产 nginx 反向代理 OSS 同路径时设为 true方案 B */
unityCdnUseSiteProxy: false,
unitycdndir: 'https://oss.eanic.cn/001_code_cocos_res_20260616',
unitycdnbuilddir: 'https://oss.eanic.cn/001_code_cocos_res_20260616/Build',
unitycdndir: 'https://oss.eanic.cn/001_code_cocos_res_20260617',
unitycdnbuilddir: 'https://oss.eanic.cn/001_code_cocos_res_20260617/Build',
python_pyodide_cdn_dir: 'https://oss.eanic.cn/001_code_python_res_20241213/pyodide/',
// 可以根据需要添加其他配置