Improve map loading functions
This commit is contained in:
@@ -1,27 +1,30 @@
|
||||
import type { PageLoad } from '/$types';
|
||||
import { error } from '@sveltejs/kit';
|
||||
|
||||
export const load: PageLoad = async ({ params, fetch }) => {
|
||||
const mapDataFiles = import.meta.glob('$lib/assets/route/*.json', { query: '?json' });
|
||||
|
||||
export const load: PageLoad = async ({ params }) => {
|
||||
const { slug } = params;
|
||||
|
||||
const path = `/src/lib/assets/route/${slug}.json`;
|
||||
console.log(`Finding path: ${path}`);
|
||||
|
||||
if (!(path in mapDataFiles)) {
|
||||
throw error(404, {
|
||||
message: `Route ${slug} not found`
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetch(`/mapFiles/json/${slug}.json`);
|
||||
|
||||
if (!res.ok) {
|
||||
throw error(404, {
|
||||
message: `Route ${slug} not found`
|
||||
});
|
||||
}
|
||||
|
||||
const rawData = await res.json();
|
||||
const rawData = await mapDataFiles[path]();
|
||||
|
||||
return {
|
||||
route: rawData,
|
||||
slug: slug
|
||||
slug: slug,
|
||||
};
|
||||
|
||||
} catch (err) {
|
||||
console.error(`Error loading map ${slug}: `, err);
|
||||
|
||||
throw error(500, {
|
||||
message: `Failed to parse map data for ${slug}`
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user