Download VPS installer with session and verify release digest
Device Core qualification / qualify (push) Successful in 6m30s

This commit is contained in:
DCCONSTRUCTIONS
2026-10-01 00:21:27 +03:00
parent 53dbd7483e
commit 539c0a60b8
+19 -4
View File
@@ -11,7 +11,25 @@ export function B2AddHost({ open, projectRef, onClose, onCreated, onError }: {
}) {
const [name, setName] = useState('ARNavi VPS'), [connection, setConnection] = useState('');
const [pending, setPending] = useState(false);
const [downloading, setDownloading] = useState(false);
const fileInput = useRef<HTMLInputElement>(null);
async function downloadInstaller() {
setDownloading(true);
try {
const response = await fetch(`/installers/${release.filename}`, { credentials: 'same-origin', signal: AbortSignal.timeout(45000) });
if (!response.ok) throw new Error('Не удалось скачать установщик. Проверьте вход в Device Core и повторите.');
const bytes = await response.arrayBuffer();
const digest = await crypto.subtle.digest('SHA-256', bytes);
const sha256 = Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, '0')).join('');
if (bytes.byteLength !== release.bytes || sha256 !== release.sha256) throw new Error('Загруженный файл не прошёл проверку. Повторите скачивание.');
const url = URL.createObjectURL(new Blob([bytes], { type: 'application/octet-stream' }));
const link = document.createElement('a'); link.href = url; link.download = release.filename;
document.body.append(link); link.click(); link.remove(); window.setTimeout(() => URL.revokeObjectURL(url), 1000);
} catch (error) {
onError(error instanceof Error && ['TimeoutError', 'AbortError'].includes(error.name)
? new Error('Сервер не успел передать установщик. Повторите скачивание.') : error);
} finally { setDownloading(false); }
}
return <Window open={open} title="Добавить VPS" size="lg" onClose={onClose} footer={
<WindowFooterActions><Button onClick={onClose}>Отмена</Button><Button type="submit" form="b2-add-vps" loading={pending} disabled={pending || !name.trim() || !connection.trim()}>Подключить VPS</Button></WindowFooterActions>
}>
@@ -27,10 +45,7 @@ export function B2AddHost({ open, projectRef, onClose, onCreated, onError }: {
<div className="b2-onboarding-grid">
<SettingsCard title="1. Установить сервер" description={`ARNavi VPS ${release.version} · Ubuntu Server 24.04 LTS · x86-64`}>
<div className="b2-settings">
<div className="b2-actions"><Button onClick={() => {
const link = document.createElement('a'); link.href = `/installers/${release.filename}`; link.download = release.filename;
document.body.append(link); link.click(); link.remove();
}}><Icon name="download" />Скачать установщик</Button></div>
<div className="b2-actions"><Button disabled={downloading} loading={downloading} onClick={downloadInstaller}><Icon name="download" />Скачать установщик</Button></div>
<p>Перенесите файл на новый VPS. В его терминале выполните команду и укажите публичный IP или домен.</p>
<TextAreaField label="Установка на VPS" rows={2} readOnly value={installCommand} />
<p>Порты сервера: 19443/TCP для API и 9922/TCP для трекеров. Ключ администратора Device Core создаётся при первой установке.</p>