Add image uploads with a media library, and event card backgrounds
Uploads (migration 028, server/src/media.js, routes/media.js): editors and up upload JPEG, PNG, GIF, WebP or SVG. Photos are resized to 2400px and saved as WebP by default, or kept as uploaded on request. Files live in UPLOADS_DIR, served by nginx in production and by the API in dev. Admins and up delete, after seeing what still uses the file. Every image field in the editor is now an image widget: preview, the path as text, Upload and Choose from library. A new Media page lists the library. Org lists and event cards now resolve logos through media.ts, so uploaded paths work there. Events get a card_image (migration 029): a photo behind the card under a light veil so the text stays readable. The card's size is unchanged. Setup for production is in docs/media-uploads.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
cd393e4ab2
commit
eaff23839f
26 changed files with 1234 additions and 22 deletions
|
|
@ -8,7 +8,10 @@
|
|||
there too.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import { mkdir } from "node:fs/promises";
|
||||
|
||||
import { serve } from "@hono/node-server";
|
||||
import { serveStatic } from "@hono/node-server/serve-static";
|
||||
import { Hono } from "hono";
|
||||
import { logger } from "hono/logger";
|
||||
|
||||
|
|
@ -24,6 +27,8 @@ import auth from "./routes/auth.js";
|
|||
import admin from "./routes/admin.js";
|
||||
import panel from "./routes/panel.js";
|
||||
import adminEntities from "./routes/admin-entities.js";
|
||||
import media from "./routes/media.js";
|
||||
import { UPLOADS_DIR } from "./media.js";
|
||||
import { startSessionSweeper } from "./auth.js";
|
||||
import { syncDescriptorsWithSchema } from "./admin-schema-sync.js";
|
||||
import { ENTITIES } from "./admin-schema.js";
|
||||
|
|
@ -39,6 +44,8 @@ const version = migrate(db);
|
|||
syncDescriptorsWithSchema(db, ENTITIES);
|
||||
|
||||
console.log(`db ${DB_PATH} (${db.driverName}, schema v${version})`);
|
||||
await mkdir(UPLOADS_DIR, { recursive: true });
|
||||
console.log(`uploads ${UPLOADS_DIR}`);
|
||||
|
||||
/* ── App ─────────────────────────────────────────────────────── */
|
||||
|
||||
|
|
@ -69,8 +76,30 @@ app.use("/api/auth/login", rateLimit({ windowMs: 15 * 60_000, max: 10 }));
|
|||
app.route("/api/admin/panel", panel);
|
||||
app.route("/api/auth", auth);
|
||||
app.route("/api/admin", admin);
|
||||
// Before the entity routes, whose /:entity would claim /media.
|
||||
app.route("/api/admin", media);
|
||||
app.route("/api/admin", adminEntities);
|
||||
|
||||
/* ── Uploads ───────────────────────────────────────────────────
|
||||
In production nginx serves /uploads/ straight from disk and
|
||||
never passes it here. This is for development, where Vite
|
||||
proxies /uploads to the API. The headers match the nginx
|
||||
block's: an uploaded SVG opened on its own can't run script.
|
||||
───────────────────────────────────────────────────────────── */
|
||||
|
||||
app.use("/uploads/*", async (c, next) => {
|
||||
await next();
|
||||
c.header("X-Content-Type-Options", "nosniff");
|
||||
c.header("Content-Security-Policy", "default-src 'none'; style-src 'unsafe-inline'; sandbox");
|
||||
});
|
||||
app.use(
|
||||
"/uploads/*",
|
||||
serveStatic({
|
||||
root: UPLOADS_DIR,
|
||||
rewriteRequestPath: (p) => p.replace(/^\/uploads/, ""),
|
||||
}),
|
||||
);
|
||||
|
||||
startSessionSweeper(db);
|
||||
|
||||
app.notFound((c) => c.json({ error: "Not found" }, 404));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue