35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import { json } from '@sveltejs/kit';
|
|
import { getRandomLieu, getRandomStreet, sanitizeRound, sanitizeRoundStreet } from '$lib/server/lieux';
|
|
import type { RequestHandler } from './$types';
|
|
|
|
/**
|
|
* GET /api/round?region=&categorie=&exclude=id1,id2 → lieu aléatoire SANITISÉ.
|
|
* Avec `mode=street` : pioche dans le corpus Mapillary (catégorie ignorée,
|
|
* réponse avec `mapillaryId` au lieu de `photo`).
|
|
*/
|
|
export const GET: RequestHandler = ({ url }) => {
|
|
if (url.searchParams.get('mode') === 'street') {
|
|
const lieu = getRandomStreet({
|
|
region: url.searchParams.get('region'),
|
|
exclude: url.searchParams.get('exclude')
|
|
});
|
|
if (!lieu) {
|
|
return json({ erreur: 'Aucun lieu street disponible pour ces critères' }, { status: 404 });
|
|
}
|
|
return json(sanitizeRoundStreet(lieu), {
|
|
headers: { 'Cache-Control': 'no-store' }
|
|
});
|
|
}
|
|
const lieu = getRandomLieu({
|
|
region: url.searchParams.get('region'),
|
|
categorie: url.searchParams.get('categorie'),
|
|
exclude: url.searchParams.get('exclude')
|
|
});
|
|
if (!lieu) {
|
|
return json({ erreur: 'Aucun lieu disponible pour ces critères' }, { status: 404 });
|
|
}
|
|
return json(sanitizeRound(lieu), {
|
|
headers: { 'Cache-Control': 'no-store' }
|
|
});
|
|
};
|