Files
photoreport/apps/app/src/api.ts
sparkandClaude Opus 5.5 a6c4c9d3b0
ci / rust (push) Successful in 13m45s
ci / typescript (push) Successful in 20m51s
Archive: newest season first, games by club initials, rematch, CPU-sized workers
Indexing goes from the newest season back (2026_2027, then 2025_2026...), latest
game first. Folders naming clubs by initials (SCP, SLB, AAAS) match their games;
named galleries are matched again after every scan. Account ids differing from
the login no longer break the walk. Archive and face workers size to the CPUs.
The viewer link follows the environment (events.next.photoreport.pt on next).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HT6iXLYUUp9pJz5Kza9xCW
2026-10-14 17:44:44 +01:00

38 lines
1.8 KiB
TypeScript

import { ApiClient } from "@photoreport/sdk";
import { desktopConfig, desktopRefreshStore, isDesktop } from "./platform.js";
/**
* Where the API is: what the desktop app says; VITE_API_URL when the build sets it; otherwise next to this page,
* app.<domain> -> api.<domain>, so a web build works on any environment without rebuilding for it.
*/
export function apiUrlFor(configured: string | undefined, location: { protocol: string; hostname: string } | undefined, desktop = desktopConfig()): string {
// The desktop app says where its API is (its interface may be a version downloaded from the web build).
if (desktop?.api) return desktop.api.replace(/\/+$/, "");
if (configured) return configured.replace(/\/+$/, "");
if (location?.hostname.startsWith("app.")) return `${location.protocol}//api.${location.hostname.slice(4)}`;
return "http://localhost:3000";
}
export const API_URL = apiUrlFor(import.meta.env.VITE_API_URL as string | undefined, typeof window === "undefined" ? undefined : window.location);
/**
* The public sites next to this API: api.<domain> -> events.<domain> (events.next.photoreport.pt for next,
* events.photoreport.pt in production), where the archive's and the events' pages are.
*/
export function eventsUrlFor(configured: string | undefined, api: string): string {
if (configured) return configured.replace(/\/+$/, "");
const u = new URL(api);
if (u.hostname.startsWith("api.")) return `${u.protocol}//events.${u.hostname.slice(4)}`;
return "http://localhost:3100";
}
export const EVENTS_URL = eventsUrlFor((import.meta.env.VITE_ARCHIVE_URL ?? import.meta.env.VITE_EVENTS_URL) as string | undefined, API_URL);
export function createApi(onSessionLost: () => void): ApiClient {
return new ApiClient({
baseUrl: API_URL,
onSessionLost,
...(isDesktop() ? { refreshStore: desktopRefreshStore } : {}),
});
}