Files
strata/apps/host/server/cloudflared-install.mjs
T
Niko1221 0b3299a019 apps/host: the owner's UI and the Node App Host
The UI source from the 14 October handoff (src/, public/, index.html, vite and
tsconfig, tests, audit-fixes, design docs) and the App Host (server/*.mjs): model
import and monitor routes, API-provider catalog and streaming (OpenAI chat, OpenAI Responses,
the Messages API), serving, tunnel, tasks, plus the host routes for Time-skip
(server/timeskip.mjs) and the tuning plan/reports. src/lib/time-skip.ts renders a real
job's own record.

The UI design is unchanged. The rebuild routed #/tuning to a new TunePanel; that is
reverted: src/screens/ModelRun.tsx and src/main.tsx are the handoff's again (#/tuning
goes where the handoff sends it), and src/components/TunePanel.tsx and
src/styles/tuning.css, which only that route used, are not carried over. Left out of
git on purpose: dist/ (build output), node_modules, and docs/evidence + docs/checkpoints
(170 MB of screenshots, kept in StrataSplit\evidence-archive).

From the owner's rebuild branch strata/rebuild-2026-10.
2026-10-15 10:24:09 +02:00

80 lines
4.3 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.
/** Install the official connector into Strata's own data folder, without sudo. */
import { createHash } from 'node:crypto';
import { execFile } from 'node:child_process';
import { mkdir, mkdtemp, lstat, rename, rm, chmod, writeFile, access } from 'node:fs/promises';
import { constants } from 'node:fs';
import { join } from 'node:path';
import { promisify } from 'node:util';
const run = promisify(execFile);
const RELEASES = 'https://api.github.com/repos/cloudflare/cloudflared/releases/latest';
const LIMIT = 128 * 1024 * 1024;
export function connectorAsset(platform, arch) {
const cpu = { x64: 'amd64', arm64: 'arm64', ia32: '386', arm: 'arm' }[arch];
if (!cpu || !['darwin', 'linux', 'win32'].includes(platform) || platform === 'win32' && arch === 'arm64') {
throw new Error('Automatic connector setup is not available for this operating system and processor.');
}
return `cloudflared-${platform === 'win32' ? 'windows' : platform}-${cpu}${platform === 'darwin' ? '.tgz' : platform === 'win32' ? '.exe' : ''}`;
}
export function verifyConnector(bytes, digest) {
if (!/^sha256:[a-f0-9]{64}$/.test(digest ?? '') || `sha256:${createHash('sha256').update(bytes).digest('hex')}` !== digest) {
throw new Error('The connector download could not be verified. Retry the automatic setup.');
}
}
export function createConnectorInstaller({ directory, platform = process.platform, arch = process.arch, fetchImpl = fetch }) {
const binary = join(directory, platform === 'win32' ? 'cloudflared.exe' : 'cloudflared');
let installing = null;
async function locate() {
try { await access(binary, platform === 'win32' ? constants.F_OK : constants.X_OK); return binary; }
catch { return null; }
}
async function install() {
const existing = await locate();
if (existing) return existing;
const name = connectorAsset(platform, arch);
await mkdir(directory, { recursive: true });
const stage = await mkdtemp(join(directory, '.install-'));
const request = url => fetchImpl(url, { signal: AbortSignal.timeout(120000), headers: { 'user-agent': 'Strata-connector-setup', accept: 'application/vnd.github+json' } });
try {
const metadata = await request(RELEASES);
if (!metadata.ok) throw new Error('Cloudflare’s download service is unavailable. Try again in a moment.');
const release = await metadata.json();
const asset = release.assets?.find(a => a.name === name);
if (!asset || !asset.browser_download_url?.startsWith('https://github.com/cloudflare/cloudflared/releases/download/')) throw new Error('No official connector download was found for this computer.');
if (asset.size > LIMIT) throw new Error('The connector download is unexpectedly large.');
const response = await request(asset.browser_download_url);
if (!response.ok || !response.body) throw new Error('The connector could not be downloaded. Check your connection and retry.');
const chunks = []; let size = 0;
for await (const chunk of response.body) {
size += chunk.byteLength;
if (size > LIMIT) throw new Error('The connector download is unexpectedly large.');
chunks.push(chunk);
}
const bytes = Buffer.concat(chunks);
verifyConnector(bytes, asset.digest);
const download = join(stage, name);
await writeFile(download, bytes, { mode: 0o600 });
let candidate = download;
if (platform === 'darwin') {
const { stdout } = await run('tar', ['-tzf', download], { timeout: 10000 });
const entry = stdout.split(/\r?\n/).find(p => p === 'cloudflared' || p === './cloudflared');
if (!entry) throw new Error('The connector package did not contain the expected executable.');
await run('tar', ['-xzf', download, '-C', stage, entry], { timeout: 10000 });
candidate = join(stage, 'cloudflared');
}
if (!(await lstat(candidate)).isFile()) throw new Error('The connector package contained an invalid executable.');
await chmod(candidate, 0o700);
await run(candidate, ['--version'], { timeout: 10000, windowsHide: true });
await rename(candidate, binary);
return binary;
} finally { await rm(stage, { recursive: true, force: true }); }
}
return { locate, ensure() {
if (!installing) installing = install().finally(() => { installing = null; });
return installing;
} };
}