app: uploaded images for announcements, campaigns and events (APP-1.0-PLAN §10)
Photos (JPEG, PNG, WebP, checked by their bytes) uploaded in the admin are turned upright, stripped of their metadata and kept at most 2000 px wide in backend/uploads (UPLOAD_DIR), served at /api/uploads (never a listing, a sandboxing CSP). Content keeps the image's full address, so an upload and an image from elsewhere work alike. 5 GB included or the licence's storage limit; an image still in use can't be deleted. The announcement, campaign and event forms get Upload a photo next to the address. Migration media. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -13,6 +13,8 @@
|
||||
* GET /jobs, PUT /jobs/:name { enabled?, cron? }, POST /jobs/:name/run Background jobs
|
||||
* GET /audit?before= the audit log; GET /access?before= the access log
|
||||
* GET /share, POST /share the App's link (and the poster), and "shared" for the checklist
|
||||
* GET /media, POST /media?alt= (the image's bytes), DELETE /media/:id uploaded images (anyone who
|
||||
* writes content: Content admin, Devotional writer, Prayer coordinator)
|
||||
*/
|
||||
import express, { type Request } from 'express';
|
||||
import { z } from 'zod';
|
||||
@@ -31,6 +33,7 @@ import { wallDay } from '../prayer/service.js';
|
||||
import { wallSettings } from '../prayer/wall.js';
|
||||
import { accessLogList, auditLog } from './logs.js';
|
||||
import { addMember, listMembers, setRoles } from './members.js';
|
||||
import { deleteMedia, listMedia, MAX_UPLOAD_BYTES, upload } from '../media/media.js';
|
||||
|
||||
const modulesBody = z.object(Object.fromEntries(APP_MODULES.map((m) => [m, z.boolean().optional()]))).strict();
|
||||
|
||||
@@ -156,6 +159,21 @@ export function adminRouter(ctx: Ctx) {
|
||||
r.get('/audit', full, handle(async (req) => ({ entries: await auditLog(ctx, { before: before(req) }) })));
|
||||
r.get('/access', full, handle(async (req) => ({ entries: await accessLogList(ctx, { before: before(req) }) })));
|
||||
|
||||
// ─── Uploaded images ───
|
||||
const writers = requireRole(ctx, ['content_admin', 'devotional_writer', 'prayer_coordinator']);
|
||||
r.get('/media', writers, handle(() => listMedia(ctx)));
|
||||
r.post('/media', writers, express.raw({ type: () => true, limit: MAX_UPLOAD_BYTES + 1 }), handle(async (req, res) => {
|
||||
const out = await upload(ctx, Buffer.isBuffer(req.body) ? req.body : Buffer.alloc(0), typeof req.query.alt === 'string' ? req.query.alt : '', req.signed!.member.id);
|
||||
await audit(ctx, { actorId: req.signed!.member.id, actorRole: req.signed!.member.roles.join(','), action: 'media_uploaded', targetType: 'media', targetId: out.id, metadata: { bytes: out.bytes }, ip: clientIp(req) });
|
||||
res.status(201);
|
||||
return out;
|
||||
}));
|
||||
r.delete('/media/:id', writers, handle(async (req) => {
|
||||
const m = await deleteMedia(ctx, String(req.params.id));
|
||||
await audit(ctx, { actorId: req.signed!.member.id, actorRole: req.signed!.member.roles.join(','), action: 'media_deleted', targetType: 'media', targetId: m.id, metadata: { name: m.filename }, ip: clientIp(req) });
|
||||
return { ok: true };
|
||||
}));
|
||||
|
||||
// ─── Share the App ───
|
||||
r.get('/share', full, handle(async () => {
|
||||
const profile = await churchProfile(ctx);
|
||||
|
||||
Reference in New Issue
Block a user