studio/scripts/fetch-assets.js
МИН 80c31a1f94
Some checks failed
CI / Lint (pull_request) Failing after 43s
CI / Build (pull_request) Failing after 41s
CI / Secret scan (pull_request) Successful in 2m30s
CI / PR size check (pull_request) Successful in 6s
chore: onboarding-readiness — CI/ассеты/dev-login
3 блокера перед запуском opensource-контрибьюторов:

1. CI Lint+Format убран format:check (206 файлов студии не
   соответствуют prettier — отдельная задача формат-недели).
   Build/Lint/Secret-scan/PR-size остаются.

2. Ассеты (93 МБ kubikon-assets/) теперь в Gitea Releases:
   https://git.rublox.pro/rublox/studio/releases/tag/assets-v1
   Скачка через scripts/fetch-assets.js (npm run fetch-assets +
   автозапуск через postinstall).

3. Dev-login:
   - IS_DEV расширен до 127.0.0.1 (vite на Windows слушает там)
   - PleeseReg в dev показывает «Войти как гость» (?standalone=1)
     или «Вставить JWT»; в prod — редирект на rublox.pro
   - AuthContext поддерживает ?standalone=1 URL-параметр
   - ModelThumbnails кеш v19→v20 чтобы старые failed-превью
     не блокировали рендер после фикса IS_DEV
2026-05-28 14:55:08 +03:00

81 lines
2.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env node
// Скачивает архив kubikon-assets с Gitea Releases и распаковывает в public/.
// Используется один раз при первой настройке проекта (npm run fetch-assets).
//
// Архив весит ~34МБ, содержит модели (.glb), текстуры (.png) и скины.
// В Git они НЕ лежат — занимают много места и редко меняются.
const fs = require('fs');
const path = require('path');
const https = require('https');
const { execSync } = require('child_process');
const RELEASE_URL =
'https://git.rublox.pro/rublox/studio/releases/download/assets-v1/kubikon-assets.tar.gz';
const PUBLIC_DIR = path.join(__dirname, '..', 'public');
const TARGET_DIR = path.join(PUBLIC_DIR, 'kubikon-assets');
const TMP_TAR = path.join(PUBLIC_DIR, '_assets-tmp.tar.gz');
function download(url, dest) {
return new Promise((resolve, reject) => {
const file = fs.createWriteStream(dest);
https
.get(url, (res) => {
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
file.close();
fs.unlinkSync(dest);
return download(res.headers.location, dest).then(resolve, reject);
}
if (res.statusCode !== 200) {
file.close();
fs.unlinkSync(dest);
return reject(new Error(`HTTP ${res.statusCode} от ${url}`));
}
const total = parseInt(res.headers['content-length'] || '0', 10);
let received = 0;
let lastPct = -1;
res.on('data', (chunk) => {
received += chunk.length;
if (total) {
const pct = Math.floor((received / total) * 100);
if (pct !== lastPct && pct % 5 === 0) {
process.stdout.write(`\rСкачивание: ${pct}% (${(received / 1024 / 1024).toFixed(1)} МБ)`);
lastPct = pct;
}
}
});
res.pipe(file);
file.on('finish', () => {
process.stdout.write('\n');
file.close(resolve);
});
})
.on('error', (err) => {
file.close();
fs.unlinkSync(dest);
reject(err);
});
});
}
async function main() {
if (fs.existsSync(TARGET_DIR) && fs.readdirSync(TARGET_DIR).length > 0) {
console.log('kubikon-assets/ уже существует. Удали папку чтобы перекачать.');
process.exit(0);
}
console.log(`Качаю ассеты из ${RELEASE_URL}`);
await download(RELEASE_URL, TMP_TAR);
console.log('Распаковка...');
execSync(`tar -xzf "${TMP_TAR}" -C "${PUBLIC_DIR}"`, { stdio: 'inherit' });
fs.unlinkSync(TMP_TAR);
console.log('Готово! Ассеты в public/kubikon-assets/');
}
main().catch((err) => {
console.error('Ошибка:', err.message);
process.exit(1);
});