Files
at-mintel/apps/sample-website/src/app/api/image/route.ts
Marc Mintel b3d089ac6d
Some checks failed
Monorepo Pipeline / ⚡ Prioritize Release (push) Successful in 2s
Monorepo Pipeline / 🏗️ Build (push) Has been cancelled
Monorepo Pipeline / 🚀 Release (push) Has been cancelled
Monorepo Pipeline / 🐳 Build Directus (Base) (push) Has been cancelled
Monorepo Pipeline / 🧹 Lint (push) Has been cancelled
Monorepo Pipeline / 🧪 Test (push) Has been cancelled
Monorepo Pipeline / 🐳 Build Gatekeeper (Product) (push) Has been cancelled
Monorepo Pipeline / 🐳 Build Build-Base (push) Has been cancelled
Monorepo Pipeline / 🐳 Build Production Runtime (push) Has been cancelled
feat(content-engine): enhance content pruning rule in orchestrator
2026-02-22 18:53:17 +01:00

46 lines
1.6 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server';
import { processImageWithSmartCrop } from '@mintel/image-processor';
export async function GET(request: NextRequest) {
const { searchParams } = new URL(request.url);
const url = searchParams.get('url');
let width = parseInt(searchParams.get('w') || '800');
let height = parseInt(searchParams.get('h') || '600');
let q = parseInt(searchParams.get('q') || '80');
if (!url) {
return NextResponse.json({ error: 'Missing url parameter' }, { status: 400 });
}
try {
// 1. Fetch image from original URL
const response = await fetch(url);
if (!response.ok) {
return NextResponse.json({ error: 'Failed to fetch original image' }, { status: response.status });
}
const arrayBuffer = await response.arrayBuffer();
const buffer = Buffer.from(arrayBuffer);
// 2. Process image with Face-API and Sharp
const processedBuffer = await processImageWithSmartCrop(buffer, {
width,
height,
format: 'webp',
quality: q,
});
// 3. Return the processed image
return new NextResponse(new Uint8Array(processedBuffer), {
status: 200,
headers: {
'Content-Type': 'image/webp',
'Cache-Control': 'public, max-age=31536000, immutable',
},
});
} catch (error) {
console.error('Image Processing Error:', error);
return NextResponse.json({ error: 'Failed to process image' }, { status: 500 });
}
}