This commit is contained in:
2025-12-06 02:31:33 +01:00
parent 2fe3f683d6
commit b76a113c4d
4 changed files with 23 additions and 45 deletions
-3
View File
@@ -12,7 +12,6 @@
"react": "19.2.1",
"react-dom": "19.2.1",
"react-icons": "^5.5.0",
"undici": "^7.16.0",
},
"devDependencies": {
"@biomejs/biome": "2.3.8",
@@ -635,8 +634,6 @@
"typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="],
"undici": ["undici@7.16.0", "", {}, "sha512-QEg3HPMll0o3t2ourKwOeUAZ159Kn9mx5pnzHRQO8+Wixmh88YdZRiIwat0iNzNNXn0yoEtXJqFpyW7eM8BV7g=="],
"undici-types": ["undici-types@7.16.0", "", {}, "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw=="],
"use-composed-ref": ["use-composed-ref@1.4.0", "", { "peerDependencies": { "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" } }, "sha512-djviaxuOOh7wkj0paeO1Q/4wMZ8Zrnag5H6yBvzN7AKKe8beOaED9SF5/ByLqsku8NP4zQqsvM2u3ew/tJK8/w=="],
+1 -2
View File
@@ -18,8 +18,7 @@
"next-themes": "^0.4.6",
"react": "19.2.1",
"react-dom": "19.2.1",
"react-icons": "^5.5.0",
"undici": "^7.16.0"
"react-icons": "^5.5.0"
},
"devDependencies": {
"@biomejs/biome": "2.3.8",
+7 -20
View File
@@ -1,11 +1,4 @@
import { type NextRequest, NextResponse } from "next/server";
import { Agent, fetch } from "undici";
const insecureAgent = new Agent({
connect: {
rejectUnauthorized: false,
},
});
export async function GET(req: NextRequest) {
try {
@@ -40,7 +33,6 @@ export async function GET(req: NextRequest) {
const externalResponse = await fetch(link, {
method: "GET",
dispatcher: insecureAgent,
});
if (!externalResponse.ok) {
@@ -50,25 +42,20 @@ export async function GET(req: NextRequest) {
);
}
const body = await externalResponse.arrayBuffer();
const headers = new Headers(externalResponse.headers);
headers.set("Cache-Control", "s-maxage=31536000, stale-while-revalidate");
const contentType = externalResponse.headers.get("content-type");
const headers = new Headers({
"Cache-Control": "s-maxage=31536000, stale-while-revalidate",
});
if (contentType) {
headers.set("Content-Type", contentType);
if (contentType === "application/pdf") {
const filename = url.pathname.split("/").pop() ?? "document.pdf";
headers.set("Content-Disposition", `inline; filename="${filename}"`);
}
if (contentType === "application/pdf") {
const filename = url.pathname.split("/").pop() ?? "document.pdf";
headers.set("Content-Disposition", `inline; filename="${filename}"`);
}
return new Response(body, {
return new NextResponse(externalResponse.body, {
status: 200,
headers,
});
} catch (e: unknown) {
console.error("Proxy Error:", e);
const errorMessage =
+15 -20
View File
@@ -1,11 +1,4 @@
import { type NextRequest, NextResponse } from "next/server";
import { Agent, fetch } from "undici";
const insecureAgent = new Agent({
connect: {
rejectUnauthorized: false,
},
});
const ALLOWED_HOSTS = [
"localhost:3000",
@@ -16,7 +9,7 @@ const ALLOWED_HOSTS = [
export async function GET(req: NextRequest) {
try {
const { searchParams } = req.nextUrl;
const link = searchParams.get("link");
let link = searchParams.get("link");
if (!link) {
return NextResponse.json({
@@ -41,26 +34,28 @@ export async function GET(req: NextRequest) {
);
}
if (url.pathname === "/api/proxy" && url.searchParams.has("link")) {
const realTarget = url.searchParams.get("link");
if (realTarget) {
try {
const realUrl = new URL(realTarget);
link = realTarget;
url = realUrl;
} catch {}
}
}
if (!ALLOWED_HOSTS.includes(url.host)) {
return NextResponse.json({ error: "Érvénytelen link" }, { status: 400 });
}
const response = await fetch(link, {
method: "HEAD",
dispatcher: insecureAgent,
});
return NextResponse.json({ status: response.status }, { status: 200 });
} catch (e: unknown) {
console.error("Validation Error:", e);
const errorResponse = {
error: "Internal Server Error",
message: e instanceof Error ? e.message : "An unexpected error occurred",
...(process.env.NODE_ENV === "development" &&
e instanceof Error && { stack: e.stack }),
};
return NextResponse.json(errorResponse, { status: 500 });
} catch (error) {
console.error("Validation Error:", error);
return NextResponse.json({ error: "Internal Server Error" }, { status: 500 });
}
}