14 changed files with 227 additions and 177 deletions
@ -1 +1,23 @@ |
|||||||
export const prerender = true; |
import NDK from '@nostr-dev-kit/ndk'; |
||||||
|
import type { LayoutLoad } from './$types'; |
||||||
|
import { standardRelays } from '$lib/consts'; |
||||||
|
import Pharos, { pharosInstance } from '$lib/parser'; |
||||||
|
|
||||||
|
export const ssr = false; |
||||||
|
|
||||||
|
export const load: LayoutLoad = () => { |
||||||
|
const ndk = new NDK({ |
||||||
|
autoConnectUserRelays: true, |
||||||
|
enableOutboxModel: true, |
||||||
|
explicitRelayUrls: standardRelays, |
||||||
|
}); |
||||||
|
ndk.connect().then(() => console.debug('ndk connected')); |
||||||
|
|
||||||
|
const parser = new Pharos(ndk); |
||||||
|
pharosInstance.set(parser); |
||||||
|
|
||||||
|
return { |
||||||
|
ndk, |
||||||
|
parser, |
||||||
|
}; |
||||||
|
}; |
||||||
|
|||||||
@ -0,0 +1,31 @@ |
|||||||
|
<script lang='ts'> |
||||||
|
import { invalidateAll, goto } from '$app/navigation'; |
||||||
|
import { Alert, P, Button } from 'flowbite-svelte'; |
||||||
|
import { ExclamationCircleOutline } from 'flowbite-svelte-icons'; |
||||||
|
import { page } from '$app/state'; |
||||||
|
</script> |
||||||
|
|
||||||
|
<main> |
||||||
|
<Alert> |
||||||
|
<div class='flex items-center space-x-2'> |
||||||
|
<ExclamationCircleOutline class='w-6 h-6' /> |
||||||
|
<span class='text-lg font-medium'> |
||||||
|
Failed to load publication. |
||||||
|
</span> |
||||||
|
</div> |
||||||
|
<P size='sm'> |
||||||
|
Alexandria failed to find one or more of the events comprising this publication. |
||||||
|
</P> |
||||||
|
<P size='xs'> |
||||||
|
{page.error?.message} |
||||||
|
</P> |
||||||
|
<div class='flex space-x-2'> |
||||||
|
<Button class='btn-leather w-fit' size='sm' onclick={() => invalidateAll()}> |
||||||
|
Try Again |
||||||
|
</Button> |
||||||
|
<Button class='btn-leather w-fit' size='sm' outline onclick={() => goto('/')}> |
||||||
|
Return to Home |
||||||
|
</Button> |
||||||
|
</div> |
||||||
|
</Alert> |
||||||
|
</main> |
||||||
@ -0,0 +1,42 @@ |
|||||||
|
import { error } from '@sveltejs/kit'; |
||||||
|
import type { NDKEvent } from '@nostr-dev-kit/ndk'; |
||||||
|
import type { PageLoad } from './$types'; |
||||||
|
import { pharosInstance } from '$lib/parser'; |
||||||
|
|
||||||
|
export const load: PageLoad = async ({ url, parent }) => { |
||||||
|
const id = url.searchParams.get('id'); |
||||||
|
const dTag = url.searchParams.get('d'); |
||||||
|
|
||||||
|
const { ndk, parser } = await parent(); |
||||||
|
|
||||||
|
let eventPromise: Promise<NDKEvent | null>; |
||||||
|
|
||||||
|
let indexEvent: NDKEvent | null; |
||||||
|
|
||||||
|
if (id) { |
||||||
|
eventPromise = ndk.fetchEvent(id) |
||||||
|
.then((ev: NDKEvent | null) => { |
||||||
|
return ev; |
||||||
|
}) |
||||||
|
.catch((err: any) => { |
||||||
|
error(404, `Failed to fetch publication root event for ID: ${id}\n${err}`); |
||||||
|
}); |
||||||
|
} else if (dTag) { |
||||||
|
eventPromise = ndk.fetchEvent({ '#d': [dTag] }) |
||||||
|
.then((ev: NDKEvent | null) => { |
||||||
|
return ev; |
||||||
|
}) |
||||||
|
.catch((err: any) => { |
||||||
|
error(404, `Failed to fetch publication root event for d tag: ${dTag}\n${err}`); |
||||||
|
}); |
||||||
|
} else { |
||||||
|
error(400, 'No publication root event ID or d tag provided.'); |
||||||
|
} |
||||||
|
|
||||||
|
indexEvent = await eventPromise as NDKEvent; |
||||||
|
const fetchPromise = parser.fetch(indexEvent); |
||||||
|
|
||||||
|
return { |
||||||
|
waitable: fetchPromise, |
||||||
|
}; |
||||||
|
}; |
||||||
Loading…
Reference in new issue