Free Motion Capture for Everyone πβ¨
TypeScript
downloadsins?
jonmatthis553aae5f8f44
diff --git a/freemocap-docs/src/components/download/DownloadPage.tsx b/freemocap-docs/src/components/download/DownloadPage.tsxindex 555ee8e9..b7189507 100644--- a/freemocap-docs/src/components/download/DownloadPage.tsx+++ b/freemocap-docs/src/components/download/DownloadPage.tsx@@ -2,13 +2,15 @@ import { useState, useMemo, useEffect } from 'react';import type { OsType, ArchType, VariantType } from './downloads';import {DEFAULT_VERSION,- getReleaseBaseUrl,buildAppDownloads,buildServerDownloads,enrichDownloadsWithAssets,+ enrichDownloadsWithR2Sizes,matchesExpectedPattern,stripVersionPrefix,hasVariant,+ isR2Hosted,+ downloadUrl,OS_NOTES,} from './downloads';import {@@ -18,6 +20,7 @@ import {import { useSystemDetection } from './hooks/useSystemDetection';import { useGpuDetection } from './hooks/useGpuDetection';import { useReleaseVersions } from './hooks/useReleaseVersions';+import { useR2FileSizes } from './hooks/useR2FileSizes';import Header from './components/Header';import SystemDetector from './components/SystemDetector';@@ -96,13 +99,22 @@ export default function DownloadPage() {);const version = stripVersionPrefix(selectedTag);- const baseUrl = getReleaseBaseUrl(version);const isLegacy = useMemo(() => {if (!selectedRelease) return false;return !matchesExpectedPattern(selectedRelease.assets, version);}, [selectedRelease, version]);+ // R2-hosted files (currently just Linux CUDA) have no GitHub asset to read a size+ // from β fetch their real size via HEAD request instead of guessing.+ const r2Urls = useMemo(() => {+ const all = [...buildAppDownloads(version), ...buildServerDownloads(version)];+ return all+ .filter(d => isR2Hosted(d.os, d.variant))+ .map(d => downloadUrl(d.file, d.os, version, d.variant));+ }, [version]);+ const r2Sizes = useR2FileSizes(r2Urls);+// Build download entries for the selected versionconst { appDownloads, serverDownloads } = useMemo(() => {let app = buildAppDownloads(version);@@ -113,8 +125,11 @@ export default function DownloadPage() {server = enrichDownloadsWithAssets(server, selectedRelease.assets);}+ app = enrichDownloadsWithR2Sizes(app, version, r2Sizes);+ server = enrichDownloadsWithR2Sizes(server, version, r2Sizes);+return { appDownloads: app, serverDownloads: server };- }, [version, selectedRelease]);+ }, [version, selectedRelease, r2Sizes]);// Sort into recommended / alternate / otherconst { recApp, altApp, otherApp, recServer, otherServer } = useMemo(() => {@@ -220,7 +235,7 @@ export default function DownloadPage() {recommended={recApp}alternates={altApp}installInstructions={appInstructions}- baseUrl={baseUrl}+ version={version}variant="primary"noDetectMessage={noDetect@@ -242,7 +257,6 @@ export default function DownloadPage() {arch={selectedArch}variant={variantForInstructions}version={version}- baseUrl={baseUrl}/>)}@@ -262,7 +276,7 @@ export default function DownloadPage() {detailsContent="Just the camera backend server binary, no GUI. Useful for headless capture rigs, remote systems you connect to over a network, or building a custom client against the FreeMoCap API. <strong>You don't need this if you downloaded the App Installer above.</strong>"recommended={recServer}installInstructions={serverInstructions}- baseUrl={baseUrl}+ version={version}variant="secondary"showTerminalTip={osForInstructions != null && osForInstructions !== 'windows'}terminalTipContent={@@ -277,7 +291,7 @@ export default function DownloadPage() {<AllPlatformsSectionotherApp={otherApp}otherServer={otherServer}- baseUrl={baseUrl}+ version={version}defaultOpen={noDetect}/></>diff --git a/freemocap-docs/src/components/download/components/AllPlatformsSection.tsx b/freemocap-docs/src/components/download/components/AllPlatformsSection.tsxindex e142b28f..edbb63db 100644--- a/freemocap-docs/src/components/download/components/AllPlatformsSection.tsx+++ b/freemocap-docs/src/components/download/components/AllPlatformsSection.tsx@@ -6,14 +6,14 @@ import styles from '../DownloadPage.module.css';interface AllPlatformsSectionProps {otherApp: DownloadEntry[];otherServer: DownloadEntry[];- baseUrl: string;+ version: string;defaultOpen?: boolean;}export default function AllPlatformsSection({otherApp,otherServer,- baseUrl,+ version,defaultOpen = false,}: AllPlatformsSectionProps) {if (otherApp.length === 0 && otherServer.length === 0) return null;@@ -35,7 +35,7 @@ export default function AllPlatformsSection({key={d.file}download={d}variant="secondary"- baseUrl={baseUrl}+ version={version}/>))}</div>@@ -52,7 +52,7 @@ export default function AllPlatformsSection({key={d.file}download={d}variant="secondary"- baseUrl={baseUrl}+ version={version}/>))}</div>diff --git a/freemocap-docs/src/components/download/components/DownloadCard.tsx b/freemocap-docs/src/components/download/components/DownloadCard.tsxindex 3938594f..b26f4a1e 100644--- a/freemocap-docs/src/components/download/components/DownloadCard.tsx+++ b/freemocap-docs/src/components/download/components/DownloadCard.tsx@@ -1,5 +1,5 @@import type { DownloadEntry } from '../downloads';-import { formatMeta } from '../downloads';+import { downloadUrl, formatMeta } from '../downloads';import styles from '../DownloadPage.module.css';type CardVariant = 'recommended' | 'server-rec' | 'secondary';@@ -7,10 +7,10 @@ type CardVariant = 'recommended' | 'server-rec' | 'secondary';interface DownloadCardProps {download: DownloadEntry;variant: CardVariant;- baseUrl: string;+ version: string;}-export default function DownloadCard({ download, variant, baseUrl }: DownloadCardProps) {+export default function DownloadCard({ download, variant, version }: DownloadCardProps) {const cardClasses = [styles.dlCard];if (variant === 'recommended') cardClasses.push(styles.dlCardRecommended);if (variant === 'server-rec') cardClasses.push(styles.dlCardServerRec, styles.dlCardServer);@@ -38,7 +38,7 @@ export default function DownloadCard({ download, variant, baseUrl }: DownloadCarreturn (<a- href={`${baseUrl}/${download.file}`}+ href={downloadUrl(download.file, download.os, version, download.variant)}className={cardClasses.join(' ')}><div className={styles.dlInfo}>diff --git a/freemocap-docs/src/components/download/components/DownloadSection.tsx b/freemocap-docs/src/components/download/components/DownloadSection.tsxindex 39493f0f..690fe3a0 100644--- a/freemocap-docs/src/components/download/components/DownloadSection.tsx+++ b/freemocap-docs/src/components/download/components/DownloadSection.tsx@@ -18,7 +18,7 @@ interface DownloadSectionProps {recommended: DownloadEntry[];alternates?: DownloadEntry[];installInstructions: InstructionBlock[];- baseUrl: string;+ version: string;variant: SectionVariant;noDetectMessage?: string;showTerminalTip?: boolean;@@ -35,7 +35,7 @@ export default function DownloadSection({recommended,alternates,installInstructions,- baseUrl,+ version,variant,noDetectMessage,showTerminalTip,@@ -74,7 +74,7 @@ export default function DownloadSection({key={d.file}download={d}variant={cardVariant}- baseUrl={baseUrl}+ version={version}/>)))}@@ -89,7 +89,7 @@ export default function DownloadSection({key={d.file}download={d}variant="secondary"- baseUrl={baseUrl}+ version={version}/>))}</div>diff --git a/freemocap-docs/src/components/download/components/TerminalInstallSection.tsx b/freemocap-docs/src/components/download/components/TerminalInstallSection.tsxindex 8de31add..4bfcfa52 100644--- a/freemocap-docs/src/components/download/components/TerminalInstallSection.tsx+++ b/freemocap-docs/src/components/download/components/TerminalInstallSection.tsx@@ -10,7 +10,6 @@ interface TerminalInstallSectionProps {arch: ArchType;variant?: VariantType;version: string;- baseUrl: string;}export default function TerminalInstallSection({@@ -18,11 +17,10 @@ export default function TerminalInstallSection({arch,variant,version,- baseUrl,}: TerminalInstallSectionProps) {if (os === 'windows' || os === 'unknown') return null;- const blocks = getTerminalInstallBlocks(os, arch, variant, version, baseUrl);+ const blocks = getTerminalInstallBlocks(os, arch, variant, version);if (blocks.length === 0) return null;return (@@ -32,8 +30,7 @@ export default function TerminalInstallSection({One-liner install from terminal</div><p className={styles.installHint}>- Download and run directly using <code>curl</code>. These pull from the- GitHub Release.+ Download and run directly using <code>curl</code>.</p>{blocks.map((block, i) =>block.codeLines ? <CodeBlock key={i} lines={block.codeLines} /> : null,diff --git a/freemocap-docs/src/components/download/downloads.ts b/freemocap-docs/src/components/download/downloads.tsindex f40b0612..8e5113d3 100644--- a/freemocap-docs/src/components/download/downloads.ts+++ b/freemocap-docs/src/components/download/downloads.ts@@ -46,6 +46,26 @@ export function getReleaseBaseUrl(version: string): string {return `https://github.com/${REPO}/releases/download/v${version}`;}+// Assets too large for a GitHub release (currently just Linux CUDA β see the+// "release" job in .github/workflows/build-installers-pyinstaller.yml) are+// hosted on Cloudflare R2 instead.+export const R2_PUBLIC_URL = 'https://pub-0a275a10417e425c94e48de393793129.r2.dev';++export function getR2BaseUrl(version: string): string {+ return `${R2_PUBLIC_URL}/${version}`;+}++/** True for the one build whose release assets live on R2 instead of GitHub. */+export function isR2Hosted(os: OsType, variant?: VariantType): boolean {+ return os === 'linux' && variant === 'cuda';+}++/** Resolves the actual download URL for a file, routing R2-hosted builds correctly. */+export function downloadUrl(file: string, os: OsType, version: string, variant?: VariantType): string {+ const base = isR2Hosted(os, variant) ? getR2BaseUrl(version) : getReleaseBaseUrl(version);+ return `${base}/${file}`;+}+// Filenames mirror the release job's naming in// .github/workflows/build-installers-pyinstaller.yml exactly:// freemocap_<version>_<matrix.label>.<ext>@@ -95,6 +115,21 @@ export function enrichDownloadsWithAssets(});}+/** R2-hosted entries have no GitHub asset to read a size from β this overlays a real,+ * measured size (from a HEAD request against the R2 object, see useR2FileSizes) instead.+ * An entry with no matching measurement is left with size: '', which renders no badge. */+export function enrichDownloadsWithR2Sizes(+ downloads: DownloadEntry[],+ version: string,+ sizeByUrl: Record<string, number>,+): DownloadEntry[] {+ return downloads.map(d => {+ if (!isR2Hosted(d.os, d.variant)) return d;+ const size = sizeByUrl[downloadUrl(d.file, d.os, version, d.variant)];+ return size != null ? { ...d, size: formatBytes(size) } : d;+ });+}+/** Check if a release's assets match our expected filename patterns */export function matchesExpectedPattern(assets: GitHubAsset[], version: string): boolean {const expectedFiles = [diff --git a/freemocap-docs/src/components/download/hooks/useR2FileSizes.ts b/freemocap-docs/src/components/download/hooks/useR2FileSizes.tsnew file mode 100644index 00000000..cc056bd8--- /dev/null+++ b/freemocap-docs/src/components/download/hooks/useR2FileSizes.ts@@ -0,0 +1,76 @@+import { useEffect, useState } from 'react';++const CACHE_KEY = 'freemocap-r2-sizes';+const CACHE_TTL_MS = 60 * 60 * 1000; // 1 hour β R2 objects are immutable per-version, longer TTL than the releases cache is fine++function readCache(): Record<string, number> {+ try {+ const raw = sessionStorage.getItem(CACHE_KEY);+ if (!raw) return {};+ const entry: { timestamp: number; data: Record<string, number> } = JSON.parse(raw);+ if (Date.now() - entry.timestamp > CACHE_TTL_MS) {+ sessionStorage.removeItem(CACHE_KEY);+ return {};+ }+ return entry.data;+ } catch {+ return {};+ }+}++function writeCache(data: Record<string, number>): void {+ try {+ sessionStorage.setItem(CACHE_KEY, JSON.stringify({ timestamp: Date.now(), data }));+ } catch {+ // sessionStorage may be full or unavailable+ }+}++/**+ * Real byte sizes for R2-hosted files, measured via HEAD request β never estimated.+ * A URL that fails to resolve (network error, CORS not configured, object missing)+ * is simply absent from the returned map; callers render no size badge for it.+ */+export function useR2FileSizes(urls: string[]): Record<string, number> {+ const [sizes, setSizes] = useState<Record<string, number>>(() => readCache());+ const key = urls.slice().sort().join(',');++ useEffect(() => {+ if (urls.length === 0) return;++ const cached = readCache();+ const missing = urls.filter(u => cached[u] == null);+ if (missing.length === 0) {+ setSizes(cached);+ return;+ }++ let cancelled = false;++ Promise.all(+ missing.map(url =>+ fetch(url, { method: 'HEAD' })+ .then(res => {+ const len = res.headers.get('content-length');+ return len ? ([url, Number(len)] as const) : null;+ })+ .catch(() => null),+ ),+ ).then(results => {+ if (cancelled) return;+ const merged = { ...cached };+ for (const r of results) {+ if (r) merged[r[0]] = r[1];+ }+ writeCache(merged);+ setSizes(merged);+ });++ return () => {+ cancelled = true;+ };+ // eslint-disable-next-line react-hooks/exhaustive-deps+ }, [key]);++ return sizes;+}diff --git a/freemocap-docs/src/components/download/installInstructions.ts b/freemocap-docs/src/components/download/installInstructions.tsindex 95721aef..e6919313 100644--- a/freemocap-docs/src/components/download/installInstructions.ts+++ b/freemocap-docs/src/components/download/installInstructions.ts@@ -1,5 +1,5 @@import type { OsType, ArchType, VariantType } from './downloads';-import { fileLabel } from './downloads';+import { downloadUrl, fileLabel } from './downloads';export interface CodeLine {type: 'prompt' | 'comment' | 'text';@@ -136,7 +136,6 @@ export function getTerminalInstallBlocks(arch: ArchType,variant: VariantType | undefined,version: string,- baseUrl: string,): InstructionBlock[] {if (os !== 'linux' && os !== 'macos') return [];@@ -151,7 +150,7 @@ export function getTerminalInstallBlocks(blocks.push({codeLines: [{ type: 'comment', content: '# App Installer β AppImage (any distro, no root)' },- { type: 'prompt', content: `curl -fSL -o freemocap.AppImage "${baseUrl}/${ai}"`, promptChar: '$' },+ { type: 'prompt', content: `curl -fSL -o freemocap.AppImage "${downloadUrl(ai, os, version, variant)}"`, promptChar: '$' },{ type: 'prompt', content: 'chmod +x freemocap.AppImage', promptChar: '$' },{ type: 'prompt', content: './freemocap.AppImage', promptChar: '$' },],@@ -159,14 +158,14 @@ export function getTerminalInstallBlocks(blocks.push({codeLines: [{ type: 'comment', content: '# App Installer β .deb (Debian/Ubuntu)' },- { type: 'prompt', content: `curl -fSL -o freemocap.deb "${baseUrl}/${deb}"`, promptChar: '$' },+ { type: 'prompt', content: `curl -fSL -o freemocap.deb "${downloadUrl(deb, os, version, variant)}"`, promptChar: '$' },{ type: 'prompt', content: 'sudo apt install ./freemocap.deb', promptChar: '$' },],});blocks.push({codeLines: [{ type: 'comment', content: '# Backend Server (headless / remote capture)' },- { type: 'prompt', content: `curl -fSL -o freemocap_server.zip "${baseUrl}/${srvZip}"`, promptChar: '$' },+ { type: 'prompt', content: `curl -fSL -o freemocap_server.zip "${downloadUrl(srvZip, os, version, variant)}"`, promptChar: '$' },{ type: 'prompt', content: 'unzip freemocap_server.zip -d freemocap_server && cd freemocap_server', promptChar: '$' },{ type: 'prompt', content: 'chmod +x freemocap_server', promptChar: '$' },{ type: 'prompt', content: './freemocap_server', promptChar: '$' },@@ -180,14 +179,14 @@ export function getTerminalInstallBlocks(blocks.push({codeLines: [{ type: 'comment', content: '# App Installer' },- { type: 'prompt', content: `curl -fSL -o freemocap.dmg "${baseUrl}/${dmg}"`, promptChar: '$' },+ { type: 'prompt', content: `curl -fSL -o freemocap.dmg "${downloadUrl(dmg, os, version, variant)}"`, promptChar: '$' },{ type: 'prompt', content: 'open freemocap.dmg', promptChar: '$' },],});blocks.push({codeLines: [{ type: 'comment', content: '# Backend Server' },- { type: 'prompt', content: `curl -fSL -o freemocap_server.zip "${baseUrl}/${srvZip}"`, promptChar: '$' },+ { type: 'prompt', content: `curl -fSL -o freemocap_server.zip "${downloadUrl(srvZip, os, version, variant)}"`, promptChar: '$' },{ type: 'prompt', content: 'unzip freemocap_server.zip -d freemocap_server && cd freemocap_server', promptChar: '$' },{ type: 'prompt', content: 'chmod +x freemocap_server && xattr -cr freemocap_server', promptChar: '$' },{ type: 'prompt', content: './freemocap_server', promptChar: '$' },