fix: first-run QA sweep of the single-container image (#413)

Fixes found by manually testing a fresh install end to end:

- auth: the must-change-password gate returned 403 on public routes
  including /api/v1/health, so every fresh install showed a false
  "Reconnecting to server" banner on the forced password change
  screen. Public routes are now exempt (they need no session at all).
  Adds the gate's first direct tests.
- multipart: @fastify/multipart's parts() iterator (9.4.0 and 10.0.0)
  ends on the request stream's "close", which on a reused keep-alive
  connection fires while an earlier part is still streaming to storage,
  silently dropping the parts behind it. The object eraser lost its
  mask file on every second POST per connection. Replaced with a
  busboy-driven iterator (lib/multipart-parts.ts) that ends on busboy's
  own "finish", installed for all routes via a preValidation hook;
  the tool-factory field-recovery workaround for the same bug is now
  unnecessary and removed.
- eraser: the mask canvas backing store is natural resolution, but
  "absolute inset-0" does not stretch replaced elements, so the
  canvas rendered at intrinsic size and the brush ring, strokes, and
  exported mask were all misscaled on photos larger than the viewport.
  The canvas now gets an explicit CSS box at the fitted size.
- compare slider: solid white divider with a dark halo so it stays
  visible over light images; still initialised at the painted region.
- tool page: the AI bundle install prompt now centers in the content
  area instead of hugging the top.
- api docs: disabled Scalar's cloud features (Ask AI, Generate MCP,
  Open API Client, dev toolbar), hid the "Powered by Scalar" footer
  link, and set the page title to "SnapOtter API Reference". The docs
  CSP blocks those cloud calls by design, so the buttons were dead UI.
- docker: embedded Redis comes from packages.redis.io pinned to the
  8.x major (was Debian's 7.0.15), matching the Compose stack and the
  documented claim. Build fails fast if the major ever drifts.
- docs: DOCKERHUB.md quick start now leads with the one-command docker
  run (matching the README) with Compose as the production path;
  README says embedded Postgres 17 + Redis 8.

Claude-Session: https://claude.ai/code/session_01XGB4pGvTvb7sUX4JN745U7
This commit is contained in:
SnapOtter
2026-07-03 19:32:25 +08:00
committed by GitHub
parent 3d4a84d068
commit bf417a509e
18 changed files with 527 additions and 242 deletions
+32 -11
View File
@@ -1,7 +1,7 @@
import { readFileSync } from "node:fs";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import scalarPlugin from "@scalar/fastify-api-reference";
import scalarPlugin, { type FastifyApiReferenceOptions } from "@scalar/fastify-api-reference";
import { SECTIONS, TOOLS, toolSection } from "@snapotter/shared";
import type { FastifyInstance } from "fastify";
import yaml from "js-yaml";
@@ -173,12 +173,23 @@ export async function docsRoutes(app: FastifyInstance): Promise<void> {
reply.type("text/yaml").send(specContent);
});
await app.register(scalarPlugin, {
routePrefix: "/api/docs",
configuration: {
content: specContent,
theme: "default",
customCss: `
// Scalar's "Ask AI" (Agent Scalar), "Generate MCP", "Open API Client", and
// the Configure/Share/Deploy toolbar are all Scalar cloud features: they
// upload or link the OpenAPI document to scalar.com, which the docs CSP
// blocks by design (self-hosted docs make no external calls). Hide them
// instead of shipping dead UI. `agent` is a source-level key the plugin's
// configuration type doesn't list yet, hence the widened type.
const configuration: NonNullable<FastifyApiReferenceOptions["configuration"]> & {
agent?: { disabled?: boolean };
} = {
content: specContent,
pageTitle: "SnapOtter API Reference",
agent: { disabled: true },
mcp: { disabled: true },
hideClientButton: true,
showDeveloperTools: "never",
theme: "default",
customCss: `
:root {
--scalar-color-1: #09090b;
--scalar-color-2: #3f3f46;
@@ -190,10 +201,20 @@ export async function docsRoutes(app: FastifyInstance): Promise<void> {
--scalar-border-color: #e4e4e7;
--scalar-font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
/* Hide the "Powered by Scalar" sidebar footer link. Scalar exposes no
config flag for it (unlike the cloud buttons disabled above). */
a[href^="https://www.scalar.com"],
a[href^="https://scalar.com"] {
display: none !important;
}
`,
hideDownloadButton: false,
hideTestRequestButton: true,
hiddenClients: true,
},
hideDownloadButton: false,
hideTestRequestButton: true,
hiddenClients: true,
};
await app.register(scalarPlugin, {
routePrefix: "/api/docs",
configuration,
});
}