Files
PacketStation/frontend/src/api/fileLocations.ts
T
spencermandClaude Opus 5.5 6e820ba0a5 Version banner, File locations section, final CSP (no unsafe-inline styles, frame-src none, object-src none)
The MTR viewer draws PDFs with pdf.js instead of an iframe the server's frame-ancestors refused.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-30 17:50:05 -06:00

54 lines
1.7 KiB
TypeScript

// Admin: the archive folder that filed packets are copied to (phase 10, api in section A of the phase 10 contract).
import { api } from "./client";
/** Who ran a check: the server may send a name or a user object. */
export type CheckedBy = string | { display_name?: string | null; sam_account?: string | null } | null;
export interface ArchiveCheck {
ok: boolean;
at: string;
by: CheckedBy;
message: string | null;
}
export interface ArchiveFailure {
seal_id: number;
packet_id: number;
packet_label: string | null;
attempts: number;
last_error: string | null;
next_try_at: string | null;
}
export interface FileLocations {
/** False when ARCHIVE_ROOT is not set on the server. */
enabled: boolean;
root: string | null;
/** The saved folder, relative to the root. */
archive_dir: string | null;
version: number;
/** The saved folder as a full path on the server. */
resolved: string | null;
last_check: ArchiveCheck | null;
copies: { pending: number; failed: number; done: number; recent_failures: ArchiveFailure[] };
}
export interface CheckResult {
ok: boolean;
resolved: string | null;
free_bytes: number | null;
message: string | null;
}
const BASE = "/api/admin/file-locations";
export const fileLocationsApi = {
get: (signal?: AbortSignal) => api.get<FileLocations>(BASE, signal),
/** Checks a folder without saving it. */
check: (archive_dir: string) => api.post<CheckResult>(`${BASE}/check`, { archive_dir }),
/** Checks and saves. 409 version_conflict when someone else saved first. */
save: (archive_dir: string, version: number) => api.put<FileLocations | null>(BASE, { archive_dir, version }),
/** Asks the worker to run the copy job now. */
retry: () => api.post<unknown>(`${BASE}/retry`, {}),
};