full upgrade to dev
This commit is contained in:
@@ -13,22 +13,28 @@ export async function GET(req: NextRequest) {
|
||||
|
||||
try {
|
||||
// Try global fetch first, fall back to node-fetch if necessary
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
let response: any;
|
||||
try {
|
||||
if (typeof (globalThis as any).fetch === 'function') {
|
||||
response = await (globalThis as any).fetch(url);
|
||||
if (
|
||||
typeof (globalThis as unknown as { fetch: unknown }).fetch ===
|
||||
"function"
|
||||
) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
response = await (globalThis as unknown as { fetch: any }).fetch(url);
|
||||
}
|
||||
} catch (e) {
|
||||
} catch (_e) {
|
||||
response = undefined;
|
||||
}
|
||||
|
||||
if (!response || typeof response.ok === 'undefined' || !response.ok) {
|
||||
if (!response || typeof response.ok === "undefined" || !response.ok) {
|
||||
try {
|
||||
const mod = await import('node-fetch');
|
||||
const nodeFetch = (mod as any).default ?? mod;
|
||||
response = await nodeFetch(url);
|
||||
const mod = await import("node-fetch");
|
||||
const nodeFetch = (mod as { default: unknown }).default ?? mod;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
response = await (nodeFetch as any)(url);
|
||||
} catch (err) {
|
||||
console.error('Failed to fetch image:', err);
|
||||
console.error("Failed to fetch image:", err);
|
||||
return NextResponse.json(
|
||||
{ error: "Failed to fetch image" },
|
||||
{ status: 500 },
|
||||
@@ -37,7 +43,9 @@ export async function GET(req: NextRequest) {
|
||||
}
|
||||
|
||||
if (!response || !response.ok) {
|
||||
throw new Error(`Failed to fetch image: ${response?.statusText ?? 'no response'}`);
|
||||
throw new Error(
|
||||
`Failed to fetch image: ${response?.statusText ?? "no response"}`,
|
||||
);
|
||||
}
|
||||
|
||||
const contentType = response.headers.get("content-type");
|
||||
|
||||
Reference in New Issue
Block a user