diff --git a/frontend/src/App.svelte b/frontend/src/App.svelte index 326b779..763d50c 100644 --- a/frontend/src/App.svelte +++ b/frontend/src/App.svelte @@ -1,8 +1,8 @@ diff --git a/frontend/src/lib/fetch.ts b/frontend/src/lib/fetch.ts index 3b8c23a..3a622bc 100644 --- a/frontend/src/lib/fetch.ts +++ b/frontend/src/lib/fetch.ts @@ -1,5 +1,5 @@ import streamSaver from "streamsaver"; -import { zData, type Distribution, zError } from "common/schema"; +import { zData, type Distribution, zError, zDumpMetadata } from "common/schema"; export async function downloadFile( dataPath: string, @@ -48,11 +48,16 @@ async function loadGzippedJson(url: string): Promise { return json; } -export async function fetchData(url: string) { - const json = await loadGzippedJson(`${url}/data.json.gz`); +export async function fetchData(portalUrl: string) { + const json = await loadGzippedJson(`${portalUrl}/data.json.gz`); if (import.meta.env.DEV) console.debug(json); return zData.parse(json); } +export async function fetchDumpMetadata(dumpUrl: string) { + const json = await loadGzippedJson(`${dumpUrl}/dump-metadata.json.gz`); + if (import.meta.env.DEV) console.debug(json); + return zDumpMetadata.parse(json); +} export async function fetchErrors(url: string) { const res = await fetchGzipped(`${url}/errors.jsonl.gz`); const text = await res.text(); diff --git a/frontend/src/lib/router.ts b/frontend/src/lib/router.ts index 20ddda4..28512e4 100644 --- a/frontend/src/lib/router.ts +++ b/frontend/src/lib/router.ts @@ -2,11 +2,12 @@ import navaid, { type Params } from "navaid"; import { writable } from "svelte/store"; export const routes = { + Dump: "/dump/:dumpUrl", Portal: "/portal/:portalUrl", Dataset: "/portal/:portalUrl/dataset/:id", }; -export type ComponentType = "NotFound" | "Portal" | "Dataset"; +export type ComponentType = "NotFound" | keyof typeof routes; type Route = { component: ComponentType; @@ -17,10 +18,9 @@ export const currentRoute = writable(); export const router = navaid(undefined, () => currentRoute.set({ component: "NotFound" }), ); -router.on(routes.Portal, (params) => - currentRoute.set({ component: "Portal", params }), -); -router.on(routes.Dataset, (params) => - currentRoute.set({ component: "Dataset", params }), -); +for (const [component, path] of Object.entries(routes)) { + router.on(path, (params) => + currentRoute.set({ component: component as keyof typeof routes, params }), + ); +} router.listen(); diff --git a/frontend/src/lib/routes/Dataset.svelte b/frontend/src/lib/routes/Dataset.svelte index 9133cd8..005d18c 100644 --- a/frontend/src/lib/routes/Dataset.svelte +++ b/frontend/src/lib/routes/Dataset.svelte @@ -1,7 +1,7 @@ + +
+
+ {#await metadataPromise} +

Cargando..

+ {:then metadata} +
+ + Viendo archivo en + {url} + + +
+ +
    + {#each metadata.sites as site} + {@const portalLink = inject(routes.Portal, { + portalUrl: encodeURIComponent(`${url}/${site.path}`), + })} +
  • +
    +
    +

    {site.title}

    +

    {site.description}

    +
    + +
    +
  • + {/each} +
+ {:catch error} + Hubo un error intenando cargar este archivo.
{error}
+ {/await} +
+
diff --git a/frontend/src/lib/routes/Portal.svelte b/frontend/src/lib/routes/Portal.svelte index 420492d..e6efa32 100644 --- a/frontend/src/lib/routes/Portal.svelte +++ b/frontend/src/lib/routes/Portal.svelte @@ -2,7 +2,7 @@ import { inject } from "regexparam"; import ArrowForward from "eva-icons/outline/svg/arrow-forward-outline.svg?component"; import ExternalLink from "eva-icons/outline/svg/external-link-outline.svg?component"; - import { fetchData, fetchErrors } from "../portal"; + import { fetchData, fetchErrors } from "../fetch"; import { routes } from "../router"; import type { Dataset } from "common/schema";