up
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
const repository = 'https://git.3crabs.space/user-penguin/gmancraft';
|
||||
|
||||
function parseLatestBuild(readme) {
|
||||
// shortcut: формат строки актуальной версии README, при его смене нужен явный manifest.
|
||||
const line = readme.split('\n').find(line => line.startsWith('Актуальная версия'));
|
||||
const match = line?.match(/^Актуальная версия\s*—\s*\*\*(\d+\.\d+\.\d+)\*\*:\s*\[Скачать \1\]\((dist\/minecraft-lab-neoforge-spike-\1\/minecraft-lab-neoforge-spike-\1\.mrpack)\)/);
|
||||
if (!match) throw new Error('Не найдена актуальная сборка');
|
||||
return { version: match[1], url: `${repository}/raw/branch/main/${match[2]}` };
|
||||
}
|
||||
|
||||
async function loadLatestBuild() {
|
||||
const status = document.getElementById('build-status');
|
||||
const download = document.getElementById('build-download');
|
||||
try {
|
||||
const response = await fetch('/minecraft/api/readme', {
|
||||
cache: 'no-store',
|
||||
signal: AbortSignal.timeout(10000),
|
||||
});
|
||||
if (!response.ok) throw new Error('README недоступен');
|
||||
const data = await response.json();
|
||||
if (data.encoding !== 'base64' || typeof data.content !== 'string') {
|
||||
throw new Error('Неизвестный формат README');
|
||||
}
|
||||
const readme = new TextDecoder().decode(Uint8Array.from(atob(data.content), char => char.charCodeAt(0)));
|
||||
const build = parseLatestBuild(readme);
|
||||
status.textContent = `Актуальная версия — ${build.version}`;
|
||||
download.href = build.url;
|
||||
download.textContent = `Скачать сборку ${build.version}`;
|
||||
download.hidden = false;
|
||||
} catch {
|
||||
status.textContent = 'Не удалось определить актуальную версию. Открой репозиторий по ссылке внизу страницы.';
|
||||
}
|
||||
}
|
||||
|
||||
loadLatestBuild();
|
||||
Reference in New Issue
Block a user