diff --git a/src/routes/[[actor=actor]]/e/[rkey]/+page.server.ts b/src/routes/[[actor=actor]]/e/[rkey]/+page.server.ts index 57e86e6..0207d9a 100644 --- a/src/routes/[[actor=actor]]/e/[rkey]/+page.server.ts +++ b/src/routes/[[actor=actor]]/e/[rkey]/+page.server.ts @@ -3,23 +3,43 @@ import type { EventData } from '$lib/cards/social/EventCard'; import { getBlentoOrBskyProfile, getRecord, resolveHandle } from '$lib/atproto/methods.js'; import { isHandle } from '@atcute/lexicons/syntax'; import { createCache, type CachedProfile } from '$lib/cache'; -import type { Did } from '@atcute/lexicons'; +import type { ActorIdentifier, Did } from '@atcute/lexicons'; +import { env as publicEnv } from '$env/dynamic/public'; -export async function load({ params, platform }) { +export async function load({ params, platform, request }) { const { rkey } = params; - const did = isHandle(params.actor) ? await resolveHandle({ handle: params.actor }) : params.actor; + + const cache = createCache(platform); + + const customDomain = request.headers.get('X-Custom-Domain')?.toLowerCase(); + + let actor: ActorIdentifier | undefined = params.actor; + + if (!actor) { + const kv = platform?.env?.CUSTOM_DOMAINS; + + if (kv && customDomain) { + try { + const did = await kv.get(customDomain); + + if (did) actor = did as ActorIdentifier; + } catch (error) { + console.error('failed to get custom domain kv', error); + } + } else { + actor = publicEnv.PUBLIC_HANDLE as ActorIdentifier; + } + } else if (customDomain && params.actor) { + actor = undefined; + } + + const did = isHandle(actor) ? await resolveHandle({ handle: actor }) : actor; if (!did || !rkey) { throw error(404, 'Event not found'); } try { - const cache = createCache(platform); - - console.log( - `https://smokesignal.events/xrpc/community.lexicon.calendar.GetEvent?repository=${encodeURIComponent(did)}&record_key=${encodeURIComponent(rkey)}` - ); - const [eventResponse, hostProfile, eventRecord] = await Promise.all([ fetch( `https://smokesignal.events/xrpc/community.lexicon.calendar.GetEvent?repository=${encodeURIComponent(did)}&record_key=${encodeURIComponent(rkey)}`