Add image upload and edit functions

This commit is contained in:
2025-12-20 16:34:50 +01:00
parent 96fa12993b
commit dfb6f7042a
72 changed files with 7413 additions and 81 deletions

View File

@ -0,0 +1,21 @@
// app/api/artworks/page/route.ts
import { getArtworksPage } from "@/lib/queryArtworks";
import { NextResponse } from "next/server";
// import { getArtworksPage } from "@/lib/artworks/query";
export async function GET(req: Request) {
const { searchParams } = new URL(req.url);
const published = (searchParams.get("published") ?? "all") as
| "all"
| "published"
| "unpublished"
| "needsWork";
const cursor = searchParams.get("cursor") ?? undefined;
const take = Number(searchParams.get("take") ?? "48");
const data = await getArtworksPage({ published, cursor, take });
return NextResponse.json(data);
}

View File

@ -0,0 +1,34 @@
import { s3 } from "@/lib/s3";
import { GetObjectCommand } from "@aws-sdk/client-s3";
import "dotenv/config";
export async function GET(req: Request, { params }: { params: { key: string[] } }) {
const { key } = await params;
const s3Key = key.join("/");
try {
const command = new GetObjectCommand({
Bucket: `${process.env.BUCKET_NAME}`,
Key: s3Key,
});
const response = await s3.send(command);
if (!response.Body) {
return new Response("No body", { status: 500 });
}
const contentType = response.ContentType ?? "application/octet-stream";
return new Response(response.Body as ReadableStream, {
headers: {
"Content-Type": contentType,
"Cache-Control": "public, max-age=3600",
"Content-Disposition": "inline", // use 'attachment' to force download
},
});
} catch (err) {
console.log(err)
return new Response("Image not found", { status: 404 });
}
}