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:
@@ -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
|
|
||||||
const regions = [
|
|
||||||
'Yasna Zakh', 'Molden Heath', 'Period Basis', 'The Bleak Lands',
|
|
||||||
'Cloud Ring', 'Paragon Soul'
|
|
||||||
];
|
|
||||||
|
|
||||||
for (const region of regions) {
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/${region}.json`);
|
const pocketbaseUrl = `https://evebase.site.quack-lab.dev/api/collections/regionview/records`;
|
||||||
if (response.ok) {
|
const response = await fetch(`${pocketbaseUrl}?filter=(sysname%3D'${systemName}')`);
|
||||||
const systems = await response.json();
|
|
||||||
const foundSystem = systems.find((s: any) => s.solarSystemName === systemName);
|
if (!response.ok) {
|
||||||
if (foundSystem) {
|
console.warn(`Failed to fetch region for system ${systemName}:`, response.status);
|
||||||
return region;
|
return null;
|
||||||
}
|
|
||||||
}
|
|
||||||
} 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;
|
return null;
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error finding region for system ${systemName}:`, error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user