-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
94e62dc
commit 57cd8b0
Showing
4 changed files
with
114 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { NextRequest, NextResponse } from "next/server"; | ||
|
||
const { BASE_URL } = process.env; | ||
|
||
export async function GET(request: NextRequest) { | ||
const searchParams = request.nextUrl.searchParams; | ||
const itemId = searchParams.get("id"); | ||
const allowedDomain = BASE_URL || "http://localhost:3000"; | ||
|
||
const referer = request.headers.get("referer"); | ||
|
||
if (!referer || !referer.startsWith(allowedDomain)) { | ||
return NextResponse.json({ error: "Forbidden" }, { status: 403 }); | ||
} | ||
|
||
if (!itemId) { | ||
return new NextResponse("Missing item ID", { status: 400 }); | ||
} | ||
|
||
try { | ||
const imageUrl = `https://mabires2.pril.cc/invimage/kr/${itemId}/${itemId}.png`; | ||
const imageResponse = await fetch(imageUrl); | ||
|
||
if (!imageResponse.ok) { | ||
return new NextResponse("Image not found", { status: 404 }); | ||
} | ||
|
||
const imageBuffer = await imageResponse.arrayBuffer(); | ||
|
||
return new NextResponse(imageBuffer, { | ||
status: 200, | ||
headers: { | ||
"Content-Type": "image/png", | ||
"Cache-Control": "public, max-age=86400", | ||
"X-Frame-Options": "DENY", | ||
"X-Content-Type-Options": "nosniff", | ||
}, | ||
}); | ||
} catch (error) { | ||
console.error("Error fetching image:", error); | ||
return new NextResponse("Error fetching image", { status: 500 }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters