mirror of
https://github.com/skidoodle/erettsegi-browser.git
synced 2026-04-28 05:27:35 +02:00
fix
This commit is contained in:
@@ -12,7 +12,6 @@
|
|||||||
"react": "19.2.1",
|
"react": "19.2.1",
|
||||||
"react-dom": "19.2.1",
|
"react-dom": "19.2.1",
|
||||||
"react-icons": "^5.5.0",
|
"react-icons": "^5.5.0",
|
||||||
"undici": "^7.16.0",
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@biomejs/biome": "2.3.8",
|
"@biomejs/biome": "2.3.8",
|
||||||
@@ -635,8 +634,6 @@
|
|||||||
|
|
||||||
"typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="],
|
"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=="],
|
"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=="],
|
"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
@@ -18,8 +18,7 @@
|
|||||||
"next-themes": "^0.4.6",
|
"next-themes": "^0.4.6",
|
||||||
"react": "19.2.1",
|
"react": "19.2.1",
|
||||||
"react-dom": "19.2.1",
|
"react-dom": "19.2.1",
|
||||||
"react-icons": "^5.5.0",
|
"react-icons": "^5.5.0"
|
||||||
"undici": "^7.16.0"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@biomejs/biome": "2.3.8",
|
"@biomejs/biome": "2.3.8",
|
||||||
|
|||||||
@@ -1,11 +1,4 @@
|
|||||||
import { type NextRequest, NextResponse } from "next/server";
|
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) {
|
export async function GET(req: NextRequest) {
|
||||||
try {
|
try {
|
||||||
@@ -40,7 +33,6 @@ export async function GET(req: NextRequest) {
|
|||||||
|
|
||||||
const externalResponse = await fetch(link, {
|
const externalResponse = await fetch(link, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
dispatcher: insecureAgent,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!externalResponse.ok) {
|
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 contentType = externalResponse.headers.get("content-type");
|
||||||
const headers = new Headers({
|
if (contentType === "application/pdf") {
|
||||||
"Cache-Control": "s-maxage=31536000, stale-while-revalidate",
|
const filename = url.pathname.split("/").pop() ?? "document.pdf";
|
||||||
});
|
headers.set("Content-Disposition", `inline; filename="${filename}"`);
|
||||||
|
|
||||||
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}"`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Response(body, {
|
return new NextResponse(externalResponse.body, {
|
||||||
status: 200,
|
status: 200,
|
||||||
headers,
|
headers,
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error("Proxy Error:", e);
|
console.error("Proxy Error:", e);
|
||||||
const errorMessage =
|
const errorMessage =
|
||||||
|
|||||||
@@ -1,11 +1,4 @@
|
|||||||
import { type NextRequest, NextResponse } from "next/server";
|
import { type NextRequest, NextResponse } from "next/server";
|
||||||
import { Agent, fetch } from "undici";
|
|
||||||
|
|
||||||
const insecureAgent = new Agent({
|
|
||||||
connect: {
|
|
||||||
rejectUnauthorized: false,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const ALLOWED_HOSTS = [
|
const ALLOWED_HOSTS = [
|
||||||
"localhost:3000",
|
"localhost:3000",
|
||||||
@@ -16,7 +9,7 @@ const ALLOWED_HOSTS = [
|
|||||||
export async function GET(req: NextRequest) {
|
export async function GET(req: NextRequest) {
|
||||||
try {
|
try {
|
||||||
const { searchParams } = req.nextUrl;
|
const { searchParams } = req.nextUrl;
|
||||||
const link = searchParams.get("link");
|
let link = searchParams.get("link");
|
||||||
|
|
||||||
if (!link) {
|
if (!link) {
|
||||||
return NextResponse.json({
|
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)) {
|
if (!ALLOWED_HOSTS.includes(url.host)) {
|
||||||
return NextResponse.json({ error: "Érvénytelen link" }, { status: 400 });
|
return NextResponse.json({ error: "Érvénytelen link" }, { status: 400 });
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await fetch(link, {
|
const response = await fetch(link, {
|
||||||
method: "HEAD",
|
method: "HEAD",
|
||||||
dispatcher: insecureAgent,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return NextResponse.json({ status: response.status }, { status: 200 });
|
return NextResponse.json({ status: response.status }, { status: 200 });
|
||||||
} catch (e: unknown) {
|
} catch (error) {
|
||||||
console.error("Validation Error:", e);
|
console.error("Validation Error:", error);
|
||||||
|
return NextResponse.json({ error: "Internal Server Error" }, { status: 500 });
|
||||||
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 });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user