app and db schema - region rename, hostname move

This commit is contained in:
Francis Cao 2025-04-24 22:42:33 -07:00
parent 5dccca0c3f
commit 12b8ac4272
19 changed files with 11252 additions and 89 deletions

View file

@ -96,12 +96,12 @@ export async function getLocation(ip: string = '', headers: Headers, hasPayloadI
// Cloudflare headers
if (headers.get('cf-ipcountry')) {
const country = decodeHeader(headers.get('cf-ipcountry'));
const subdivision1 = decodeHeader(headers.get('cf-region-code'));
const region = decodeHeader(headers.get('cf-region-code'));
const city = decodeHeader(headers.get('cf-ipcity'));
return {
country,
subdivision1: getRegionCode(country, subdivision1),
region: getRegionCode(country, region),
city,
};
}
@ -109,12 +109,12 @@ export async function getLocation(ip: string = '', headers: Headers, hasPayloadI
// Vercel headers
if (headers.get('x-vercel-ip-country')) {
const country = decodeHeader(headers.get('x-vercel-ip-country'));
const subdivision1 = decodeHeader(headers.get('x-vercel-ip-country-region'));
const region = decodeHeader(headers.get('x-vercel-ip-country-region'));
const city = decodeHeader(headers.get('x-vercel-ip-city'));
return {
country,
subdivision1: getRegionCode(country, subdivision1),
region: getRegionCode(country, region),
city,
};
}
@ -131,14 +131,12 @@ export async function getLocation(ip: string = '', headers: Headers, hasPayloadI
if (result) {
const country = result.country?.iso_code ?? result?.registered_country?.iso_code;
const subdivision1 = result.subdivisions?.[0]?.iso_code;
const subdivision2 = result.subdivisions?.[1]?.names?.en;
const region = result.subdivisions?.[0]?.iso_code;
const city = result.city?.names?.en;
return {
country,
subdivision1: getRegionCode(country, subdivision1),
subdivision2,
region: getRegionCode(country, region),
city,
};
}
@ -149,14 +147,13 @@ export async function getClientInfo(request: Request, payload: Record<string, an
const ip = payload?.ip || getIpAddress(request.headers);
const location = await getLocation(ip, request.headers, !!payload?.ip);
const country = location?.country;
const subdivision1 = location?.subdivision1;
const subdivision2 = location?.subdivision2;
const region = location?.region;
const city = location?.city;
const browser = browserName(userAgent);
const os = detectOS(userAgent) as string;
const device = getDevice(payload?.screen, os);
return { userAgent, browser, os, ip, country, subdivision1, subdivision2, city, device };
return { userAgent, browser, os, ip, country, region, city, device };
}
export function hasBlockedIp(clientIp: string) {