P1-0: V8 heap cap (HOMARR_MAX_OLD_SPACE_SIZE, default 512MB)
P1-1: Module graph cuts
- Dynamic integration imports (55 static → lazy loaders)
- Conditional DB driver loading (only configured driver loaded)
- Replace jsdom with linkedom for SVG sanitization
- Delete eager widget barrel (55 import * as → 0)
- Extract createRetryableLoader to @homarr/common
P1-2: Enable cacheComponents + restructure root layout
- Suspense boundaries around session-dependent providers
- ColorSchemeScript replaces server-side cookie reads
- Board/manage/auth layouts wrapped in Suspense
P1-3: Cache read paths
- Cache tag registry + invalidation helpers
- Cache invalidation wired into all mutation routers
- Translation deep-merge memoized per locale
P1-4: Prerendered shells + loading.tsx files
P1-5: Shared integration data cache (60s TTL, stale-while-revalidate)
P1-6: Redis-backed Next.js cache handler (@homarr/next-cache-handler)
P1-7: Redis optional (memory channel fallback), TTL on pubSub:last:*,
Redis clients consolidated from 6 to 2
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
import { notFound } from "next/navigation";
|
|
import { NextResponse } from "next/server";
|
|
import type { NextRequest } from "next/server";
|
|
|
|
import { db, eq } from "@homarr/db";
|
|
import { medias } from "@homarr/db/schema";
|
|
|
|
import { sanitizeSvg } from "../svg-purify";
|
|
|
|
export async function GET(_req: NextRequest, props: { params: Promise<{ id: string }> }) {
|
|
const params = await props.params;
|
|
const image = await db.query.medias.findFirst({
|
|
where: eq(medias.id, params.id),
|
|
columns: {
|
|
content: true,
|
|
contentType: true,
|
|
},
|
|
});
|
|
|
|
if (!image) {
|
|
notFound();
|
|
}
|
|
|
|
let content = new Uint8Array(image.content);
|
|
|
|
// Sanitize SVG content to prevent XSS attacks
|
|
if (image.contentType === "image/svg+xml" || image.contentType === "image/svg") {
|
|
const svgText = new TextDecoder().decode(content);
|
|
const sanitized = sanitizeSvg(svgText);
|
|
content = new TextEncoder().encode(sanitized);
|
|
}
|
|
|
|
const headers = new Headers();
|
|
headers.set("Content-Type", image.contentType);
|
|
headers.set("Content-Length", content.length.toString());
|
|
headers.set("Content-Security-Policy", "default-src 'none'; style-src 'unsafe-inline'; sandbox");
|
|
headers.set("X-Content-Type-Options", "nosniff");
|
|
|
|
return new NextResponse(content, {
|
|
status: 200,
|
|
headers,
|
|
});
|
|
}
|