chore: add prettier formatting
All checks were successful
CI / Lint, typecheck and build (push) Successful in 9m56s
All checks were successful
CI / Lint, typecheck and build (push) Successful in 9m56s
This commit is contained in:
@@ -30,26 +30,31 @@ export async function GET(request: Request) {
|
||||
try {
|
||||
const response = await fetch(`${GEOCODING_URL}?${params}`, { next: { revalidate: 86400 } });
|
||||
if (!response.ok) return NextResponse.json({ error: "Location search is unavailable." }, { status: 502 });
|
||||
const data = await response.json() as { results?: RawLocation[] };
|
||||
const data = (await response.json()) as { results?: RawLocation[] };
|
||||
const results = (data.results ?? []).flatMap((location) => {
|
||||
if (!location.id || !location.name || !Number.isFinite(location.latitude) || !Number.isFinite(location.longitude)) return [];
|
||||
if (!location.id || !location.name || !Number.isFinite(location.latitude) || !Number.isFinite(location.longitude))
|
||||
return [];
|
||||
const countryCode = location.country_code?.toUpperCase() ?? null;
|
||||
return [{
|
||||
id: location.id,
|
||||
name: location.name,
|
||||
latitude: location.latitude as number,
|
||||
longitude: location.longitude as number,
|
||||
province: location.admin1 ?? null,
|
||||
district: location.admin2 ?? null,
|
||||
country: location.country ?? null,
|
||||
countryCode,
|
||||
admin1: location.admin1 ?? null,
|
||||
admin2: location.admin2 ?? null,
|
||||
timezone: location.timezone ?? null,
|
||||
region: getWeatherRegionForCountryCode(countryCode),
|
||||
}];
|
||||
return [
|
||||
{
|
||||
id: location.id,
|
||||
name: location.name,
|
||||
latitude: location.latitude as number,
|
||||
longitude: location.longitude as number,
|
||||
province: location.admin1 ?? null,
|
||||
district: location.admin2 ?? null,
|
||||
country: location.country ?? null,
|
||||
countryCode,
|
||||
admin1: location.admin1 ?? null,
|
||||
admin2: location.admin2 ?? null,
|
||||
timezone: location.timezone ?? null,
|
||||
region: getWeatherRegionForCountryCode(countryCode),
|
||||
},
|
||||
];
|
||||
});
|
||||
return NextResponse.json(results, {
|
||||
headers: { "Cache-Control": "public, s-maxage=86400, stale-while-revalidate=604800" },
|
||||
});
|
||||
return NextResponse.json(results, { headers: { "Cache-Control": "public, s-maxage=86400, stale-while-revalidate=604800" } });
|
||||
} catch {
|
||||
return NextResponse.json({ error: "Location search is unavailable." }, { status: 502 });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user