fix: harden the vault before release
Require a private passphrase and loopback-or-token admin auth. New vaults use Argon2id; existing PBKDF2 vaults still open, and new snapshot metadata is encrypted. Wormhole tokens survive restart, offset uploads seal into the vault, and client-certificate uploads are real. Reject the command provider and keep Postgres passwords off the process arguments. Keep the interruptible canvas motion.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { useCallback, useLayoutEffect, useMemo, useRef, useState } from "react";
|
||||
import { animate, spring, useMotionValue } from "motion/react";
|
||||
import type { Orbit, Snapshot } from "../../api";
|
||||
import { orbitStatus } from "../../lib/format";
|
||||
import { LABEL_HEIGHT, placeLabels, type Rect } from "../../lib/galaxyLabelLayout";
|
||||
@@ -7,6 +8,7 @@ import {
|
||||
SCENE_HEIGHT, SCENE_WIDTH, spiralPoint, type Vec2,
|
||||
} from "../../lib/galaxyLayout";
|
||||
import { useGalaxyMotion } from "../../hooks/useGalaxyMotion";
|
||||
import { uiSpring } from "../../lib/motion";
|
||||
import { VaultCore } from "./VaultCore";
|
||||
|
||||
export type CaptureArrival = { orbitId: string; snapshotId: string };
|
||||
@@ -16,6 +18,7 @@ type Props = {
|
||||
selectedOrbitId?: string;
|
||||
recentSnapshots: Snapshot[];
|
||||
flowing: boolean;
|
||||
reducedMotion: boolean;
|
||||
arrival?: CaptureArrival;
|
||||
onSelectOrbit: (id: string) => void;
|
||||
onSelectSnapshot: (id: string) => void;
|
||||
@@ -25,22 +28,38 @@ const HALF_WIDTH = SCENE_WIDTH / 2;
|
||||
const HALF_HEIGHT = SCENE_HEIGHT / 2;
|
||||
const labelFont = "500 11px ui-monospace, monospace";
|
||||
const MAX_LABELS = 12;
|
||||
const METEOR_SECONDS = 1.4;
|
||||
const ACCRETION_SECONDS = 6.4;
|
||||
|
||||
export function BlackholeGalaxy({
|
||||
orbits, selectedOrbitId, recentSnapshots, flowing, arrival, onSelectOrbit, onSelectSnapshot,
|
||||
orbits, selectedOrbitId, recentSnapshots, flowing, reducedMotion, arrival, onSelectOrbit, onSelectSnapshot,
|
||||
}: Props) {
|
||||
const frame = useRef<HTMLDivElement>(null);
|
||||
const bodyNodes = useRef(new Map<SVGGElement, { id: string; far: boolean }>());
|
||||
const slotsBefore = useRef<ReturnType<typeof assignOrbitSlots>>(undefined);
|
||||
const elapsed = useRef(0);
|
||||
const core = useRef<SVGGElement>(null);
|
||||
const meteor = useRef<{ id: string; time: number; source: Vec2 }>(undefined);
|
||||
const meteor = useRef<{ id: string; time: number; source: Vec2; progress: ReturnType<typeof spring> }>(undefined);
|
||||
const trail = useRef<SVGPathElement>(null);
|
||||
const head = useRef<SVGCircleElement>(null);
|
||||
const effect = useRef<SVGGElement>(null);
|
||||
const [width, setWidth] = useState(0);
|
||||
const [coasting, setCoasting] = useState(false);
|
||||
const rate = useMotionValue(flowing && !reducedMotion ? 1 : 0);
|
||||
const moving = !reducedMotion && (flowing || coasting);
|
||||
|
||||
useLayoutEffect(() => () => rate.stop(), [rate]);
|
||||
useLayoutEffect(() => {
|
||||
if (reducedMotion) {
|
||||
rate.jump(0);
|
||||
setCoasting(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const target = flowing ? 1 : 0;
|
||||
if (rate.get() === target && !rate.isAnimating()) return;
|
||||
setCoasting(!flowing);
|
||||
animate(rate, target, { ...uiSpring, onComplete: () => setCoasting(false) });
|
||||
}, [flowing, rate, reducedMotion]);
|
||||
|
||||
const slots = useMemo(
|
||||
() => assignOrbitSlots(orbits.map(({ id }) => id), slotsBefore.current, selectedOrbitId),
|
||||
@@ -58,8 +77,8 @@ export function BlackholeGalaxy({
|
||||
}, []);
|
||||
|
||||
const draw = useCallback((delta: number) => {
|
||||
if (flowing && delta > 0) {
|
||||
elapsed.current += delta;
|
||||
if (moving && delta > 0) {
|
||||
elapsed.current += delta * Math.max(0, rate.get());
|
||||
const phase = (elapsed.current % ACCRETION_SECONDS) / ACCRETION_SECONDS;
|
||||
core.current?.style.setProperty("--accretion-offset", String(-100 * phase));
|
||||
}
|
||||
@@ -74,37 +93,42 @@ export function BlackholeGalaxy({
|
||||
node.setAttribute("transform", `translate(${x} ${y})`);
|
||||
}
|
||||
|
||||
if (!arrival) {
|
||||
if (!arrival || reducedMotion) {
|
||||
effect.current?.setAttribute("opacity", "0");
|
||||
return flowing;
|
||||
return moving;
|
||||
}
|
||||
const slot = slots.get(arrival.orbitId);
|
||||
if (meteor.current?.id !== arrival.snapshotId && slot) {
|
||||
const source = orbitPose(slot, elapsed.current);
|
||||
meteor.current = { id: arrival.snapshotId, time: 0, source };
|
||||
meteor.current = {
|
||||
id: arrival.snapshotId,
|
||||
time: 0,
|
||||
source,
|
||||
progress: spring({ ...uiSpring, stiffness: 36, damping: 12, keyframes: [0, 1], restDelta: 0.002 }),
|
||||
};
|
||||
const points = Array.from({ length: 36 }, (_, i) => spiralPoint(source, i / 35));
|
||||
trail.current?.setAttribute("d", points.map(({ x, y }, i) => `${i ? "L" : "M"} ${x} ${y}`).join(" "));
|
||||
}
|
||||
const current = meteor.current;
|
||||
if (!current || current.id !== arrival.snapshotId) return flowing;
|
||||
current.time += delta;
|
||||
const progress = Math.min(1, current.time / METEOR_SECONDS);
|
||||
if (!current || current.id !== arrival.snapshotId) return moving;
|
||||
current.time += delta * 1000;
|
||||
const { value: progress, done } = current.progress.next(current.time);
|
||||
const { x, y } = spiralPoint(current.source, progress);
|
||||
head.current?.setAttribute("cx", String(x));
|
||||
head.current?.setAttribute("cy", String(y));
|
||||
trail.current?.setAttribute("stroke-dashoffset", String(0.2 - progress));
|
||||
effect.current?.setAttribute("opacity", String(progress >= 1 ? 0 : Math.min(1, (1 - progress) * 6)));
|
||||
return flowing || progress < 1;
|
||||
}, [arrival, flowing, slots]);
|
||||
return moving || !done;
|
||||
}, [arrival, moving, rate, reducedMotion, slots]);
|
||||
|
||||
useGalaxyMotion(flowing || !!arrival, draw);
|
||||
useGalaxyMotion(moving || (!reducedMotion && !!arrival), draw);
|
||||
|
||||
const scale = width / SCENE_WIDTH;
|
||||
const height = SCENE_HEIGHT * scale;
|
||||
const hitRadius = Math.max(12, scale ? 12 / scale : 12);
|
||||
const selectedSlot = selectedOrbitId ? slots.get(selectedOrbitId) : undefined;
|
||||
const selectedPosition = !flowing && selectedSlot ? orbitPose(selectedSlot, elapsed.current) : undefined;
|
||||
const positions = !flowing ? [...slots.values()].map((slot) => orbitPose(slot, elapsed.current)) : [];
|
||||
const selectedPosition = !moving && selectedSlot ? orbitPose(selectedSlot, elapsed.current) : undefined;
|
||||
const positions = !moving ? [...slots.values()].map((slot) => orbitPose(slot, elapsed.current)) : [];
|
||||
const moons = selectedPosition
|
||||
? moonPoses(selectedPosition, recentSnapshots.length, 2 * hitRadius + 3, positions)
|
||||
: [];
|
||||
@@ -122,7 +146,7 @@ export function BlackholeGalaxy({
|
||||
};
|
||||
|
||||
let labels: ReturnType<typeof placeLabels> = [];
|
||||
if (!flowing && width && labelCandidates.length) {
|
||||
if (!moving && width && labelCandidates.length) {
|
||||
const measure = document.createElement("canvas").getContext("2d");
|
||||
if (measure) measure.font = labelFont;
|
||||
const markers = positions.map((point) => box(point, 7));
|
||||
|
||||
Reference in New Issue
Block a user