2026-02-14 00:59:57 +01:00
|
|
|
/**
|
|
|
|
|
* EXIF metadata API route — returns camera/lens/settings info for an asset.
|
|
|
|
|
* Called on-demand by the lightbox when the user clicks "Info".
|
|
|
|
|
*
|
|
|
|
|
* The :token is an encoded asset ID (not a raw UUID).
|
|
|
|
|
*/
|
|
|
|
|
|
2026-03-12 11:30:45 +00:00
|
|
|
import { NextRequest, NextResponse } from 'next/server';
|
2026-02-14 00:59:57 +01:00
|
|
|
import { immich } from '@/lib/immich';
|
|
|
|
|
import { decodeAssetId } from '@/lib/tokens';
|
2026-03-07 08:19:20 +01:00
|
|
|
import { getConfig } from '@/lib/config';
|
2026-03-15 07:41:49 +01:00
|
|
|
import { checkRateLimit, getClientIp } from '@/lib/rate-limit';
|
2026-02-14 00:59:57 +01:00
|
|
|
|
2026-03-12 11:30:45 +00:00
|
|
|
export async function GET(request: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
2026-03-07 08:19:20 +01:00
|
|
|
const config = getConfig();
|
|
|
|
|
|
|
|
|
|
// Security: If EXIF is globally disabled, do not serve it via API either
|
|
|
|
|
if (!config.exifOnHover) {
|
|
|
|
|
return NextResponse.json({ error: 'EXIF metadata is disabled' }, { status: 403 });
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-12 11:30:45 +00:00
|
|
|
// ── Rate limiting ──────────────────────────────────
|
2026-03-15 07:41:49 +01:00
|
|
|
const ip = getClientIp(request);
|
2026-03-12 11:30:45 +00:00
|
|
|
const { success, resetAt } = checkRateLimit(`exif:${ip}`, config.rateLimitRpm);
|
|
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
|
const retryAfter = Math.ceil((resetAt - Date.now()) / 1000);
|
|
|
|
|
console.warn(`[EXIF API] ⚠️ Rate limit exceeded for IP: ${ip}. Retry after ${retryAfter}s`);
|
|
|
|
|
return NextResponse.json({ error: 'Too many requests' }, { status: 429 });
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-14 11:47:26 +01:00
|
|
|
const { id: token } = await params;
|
2026-02-14 00:59:57 +01:00
|
|
|
|
2026-02-14 11:47:26 +01:00
|
|
|
// Decode the opaque token back to an Immich asset ID
|
|
|
|
|
const assetId = decodeAssetId(token);
|
|
|
|
|
if (!assetId) {
|
|
|
|
|
return NextResponse.json({ error: 'Invalid token' }, { status: 400 });
|
|
|
|
|
}
|
2026-02-14 00:59:57 +01:00
|
|
|
|
2026-02-14 11:47:26 +01:00
|
|
|
const asset = await immich.getAssetInfo(assetId);
|
|
|
|
|
if (!asset?.exifInfo) {
|
|
|
|
|
return NextResponse.json({ error: 'No EXIF data' }, { status: 404 });
|
|
|
|
|
}
|
2026-02-14 00:59:57 +01:00
|
|
|
|
2026-02-14 11:47:26 +01:00
|
|
|
const exif = asset.exifInfo;
|
2026-03-07 08:18:23 +01:00
|
|
|
return NextResponse.json(
|
|
|
|
|
{
|
|
|
|
|
make: exif.make,
|
|
|
|
|
model: exif.model,
|
|
|
|
|
lensModel: exif.lensModel,
|
|
|
|
|
focalLength: exif.focalLength,
|
|
|
|
|
fNumber: exif.fNumber,
|
|
|
|
|
exposureTime: exif.exposureTime,
|
|
|
|
|
iso: exif.iso,
|
|
|
|
|
city: exif.city,
|
|
|
|
|
country: exif.country,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
headers: {
|
|
|
|
|
'Cache-Control': 'private, max-age=86400, stale-while-revalidate=3600',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
);
|
2026-02-14 00:59:57 +01:00
|
|
|
}
|