mirror of
https://gitbruv.vercel.app/api/git/bruv/gitbruv.git
synced 2025-12-20 23:24:09 +01:00
wip
This commit is contained in:
parent
a63628e659
commit
dffc97239e
17 changed files with 1220 additions and 24 deletions
35
app/api/avatar/[filename]/route.ts
Normal file
35
app/api/avatar/[filename]/route.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { r2Get } from "@/lib/r2";
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ filename: string }> }
|
||||
) {
|
||||
const { filename } = await params;
|
||||
|
||||
const key = `avatars/${filename}`;
|
||||
const data = await r2Get(key);
|
||||
|
||||
if (!data) {
|
||||
return new NextResponse(null, { status: 404 });
|
||||
}
|
||||
|
||||
const ext = filename.split(".").pop()?.toLowerCase();
|
||||
let contentType = "image/png";
|
||||
|
||||
if (ext === "jpg" || ext === "jpeg") {
|
||||
contentType = "image/jpeg";
|
||||
} else if (ext === "gif") {
|
||||
contentType = "image/gif";
|
||||
} else if (ext === "webp") {
|
||||
contentType = "image/webp";
|
||||
}
|
||||
|
||||
return new NextResponse(data, {
|
||||
headers: {
|
||||
"Content-Type": contentType,
|
||||
"Cache-Control": "public, max-age=31536000, immutable",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue