* feat: add media management * feat: add missing page search item * fix: medias should be hidden for anonymous users * chore: rename show-all to include-from-all-users * fix: inconsistent table column for creator-id of media * fix: schema check not working because of custom type for blob in mysql * chore: temporarily remove migrations * chore: readd removed migrations
30 lines
743 B
TypeScript
30 lines
743 B
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/sqlite";
|
|
|
|
export async function GET(_req: NextRequest, { params }: { params: { id: string } }) {
|
|
const image = await db.query.medias.findFirst({
|
|
where: eq(medias.id, params.id),
|
|
columns: {
|
|
content: true,
|
|
contentType: true,
|
|
},
|
|
});
|
|
|
|
if (!image) {
|
|
notFound();
|
|
}
|
|
|
|
const headers = new Headers();
|
|
headers.set("Content-Type", image.contentType);
|
|
headers.set("Content-Length", image.content.length.toString());
|
|
|
|
return new NextResponse(image.content, {
|
|
status: 200,
|
|
headers,
|
|
});
|
|
}
|