This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

core / web / src / lib / server / repo.ts
1.6 kB 45 lines
1import { error } from "@sveltejs/kit"; 2import { createBobbinClient, type BobbinContext } from "$lib/api/client"; 3import { gitTarget, type GitTarget } from "$lib/api/gitclient"; 4import { resolveMiniDoc, type MiniDoc } from "$lib/api/identity"; 5import { toHttpError } from "$lib/api/load"; 6import type { RecordView, RepoRecord } from "$lib/api/records"; 7import { resolveRepoByName } from "$lib/api/repo"; 8import { getConfig } from "$lib/server/config"; 9 10export interface ResolvedRepo { 11 ctx: BobbinContext; 12 git: GitTarget; 13 doc: MiniDoc; 14 view: RecordView<RepoRecord>; 15} 16 17// the handle/repo preamble shared by the raw-content routes, params arrive 18// already decoded 19export const resolveRepoFromParams = async (event: { 20 params: { handle?: string; repo?: string }; 21 fetch: typeof fetch; 22}): Promise<ResolvedRepo> => { 23 const identifier = event.params.handle ?? ""; 24 const name = event.params.repo ?? ""; 25 26 // rejects bare words, unrelated paths must 404 instead of resolving as actors 27 if (!identifier.startsWith("did:") && !identifier.includes(".")) { 28 error(404, "Not found"); 29 } 30 31 const config = getConfig(); 32 const ctx = createBobbinClient({ serviceUrl: config.bobbinUrl, fetch: event.fetch }); 33 34 const doc = await resolveMiniDoc(ctx, identifier).catch((cause) => 35 toHttpError(cause, "Could not resolve user") 36 ); 37 const view = await resolveRepoByName(ctx, doc.did, name).catch((cause) => 38 toHttpError(cause, "Could not load repository") 39 ); 40 if (!view) error(404, `${doc.handle}/${name} does not exist`); 41 42 const git = gitTarget(config, { uri: view.uri, repoDid: view.value.repoDid }, event.fetch); 43 44 return { ctx, git, doc, view }; 45};