mirror of
https://github.com/placeholder-soft/web.git
synced 2026-01-12 22:45:00 +08:00
require response content-type be an image (#1052)
This commit is contained in:
@@ -14,6 +14,11 @@ export async function GET(request: NextRequest) {
|
||||
throw new Error(`Failed to fetch image: ${response.statusText}`);
|
||||
}
|
||||
const contentType = response.headers.get('content-type');
|
||||
|
||||
if (!contentType || !contentType.startsWith('image') || contentType.includes('svg')) {
|
||||
return NextResponse.json({ error: 'Unsupported content type' }, { status: 400 });
|
||||
}
|
||||
|
||||
const imageBuffer = await response.arrayBuffer();
|
||||
return new NextResponse(imageBuffer, {
|
||||
status: 200,
|
||||
@@ -23,7 +28,6 @@ export async function GET(request: NextRequest) {
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error fetching image:', error);
|
||||
return NextResponse.json({ error: 'Failed to fetch image' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user