Refactor: Use Pocketbase for region lookup

Replace the local `findSystemRegion` function with a Pocketbase API call to fetch region data.
This commit is contained in:
gpt-engineer-app[bot]
2025-06-14 15:44:29 +00:00
parent 988e907c48
commit f7a1394cb1

View File

@@ -1,26 +1,26 @@
// Utility to find which region a system belongs to // Utility to find which region a system belongs to using pocketbase API
export const findSystemRegion = async (systemName: string): Promise<string | null> => { export const findSystemRegion = async (systemName: string): Promise<string | null> => {
// List of all region files we have try {
const regions = [ const pocketbaseUrl = `https://evebase.site.quack-lab.dev/api/collections/regionview/records`;
'Yasna Zakh', 'Molden Heath', 'Period Basis', 'The Bleak Lands', const response = await fetch(`${pocketbaseUrl}?filter=(sysname%3D'${systemName}')`);
'Cloud Ring', 'Paragon Soul'
]; if (!response.ok) {
console.warn(`Failed to fetch region for system ${systemName}:`, response.status);
for (const region of regions) { return null;
try {
const response = await fetch(`/${region}.json`);
if (response.ok) {
const systems = await response.json();
const foundSystem = systems.find((s: any) => s.solarSystemName === systemName);
if (foundSystem) {
return region;
}
}
} catch (error) {
console.warn(`Failed to load region ${region}:`, error);
} }
const data = await response.json();
console.log('Region lookup response for', systemName, ':', data);
if (data.items && data.items.length > 0) {
return data.items[0].sysregion;
}
console.warn(`No region found for system: ${systemName}`);
return null;
} catch (error) {
console.error(`Error finding region for system ${systemName}:`, error);
return null;
} }
return null;
}; };