diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..33f1597 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,4 @@ +{ + "printWidth": 96, + "arrowParens": "avoid" +} diff --git a/appview/db.ts b/appview/db.ts index 1095cac..6493cd7 100644 --- a/appview/db.ts +++ b/appview/db.ts @@ -20,19 +20,12 @@ CREATE TABLE IF NOT EXISTS videos ( `); const selectAllowlist = conn.prepare("SELECT 1 FROM allowlist WHERE repo = ?"); -const selectVideo = conn.prepare( - "SELECT filename FROM videos WHERE repo = ? AND cid = ?" -); -const insertVideo = conn.prepare( - "INSERT INTO videos (repo, cid, filename) VALUES (?, ?, ?)" -); +const selectVideo = conn.prepare("SELECT filename FROM videos WHERE repo = ? AND cid = ?"); +const insertVideo = conn.prepare("INSERT INTO videos (repo, cid, filename) VALUES (?, ?, ?)"); export const db = { db: conn, - inAllowlist: (did: string) => - (selectAllowlist.value<[boolean]>(did)?.[0] && true) ?? false, - getVideo: (did: string, cid: string) => - selectVideo.value<[string]>(did, cid)?.[0], - addVideo: (did: string, cid: string, filename: string) => - insertVideo.run(did, cid, filename), + inAllowlist: (did: string) => (selectAllowlist.value<[boolean]>(did)?.[0] && true) ?? false, + getVideo: (did: string, cid: string) => selectVideo.value<[string]>(did, cid)?.[0], + addVideo: (did: string, cid: string, filename: string) => insertVideo.run(did, cid, filename), }; diff --git a/appview/main.ts b/appview/main.ts index ba61bab..37ca29b 100644 --- a/appview/main.ts +++ b/appview/main.ts @@ -4,20 +4,9 @@ import { serveDir, serveFile } from "@std/http/file-server"; import * as z from "@zod/mini"; import { db } from "./db.ts"; -import { - CompositeDidDocumentResolver, - PlcDidDocumentResolver, - WebDidDocumentResolver, -} from "@atcute/identity-resolver"; +import { resolveDid } from "../common/identity.ts"; import { VIDEO_PATTERN } from "../common/routes.ts"; -const didResolver = new CompositeDidDocumentResolver({ - methods: { - plc: new PlcDidDocumentResolver(), - web: new WebDidDocumentResolver(), - }, -}); - async function fetchVideo(req: Request): Promise { if (req.method === "OPTIONS") { return new Response(null, { @@ -59,18 +48,13 @@ async function fetchVideo(req: Request): Promise { "content-type": "application/json", "access-control-allow-origin": "*", }, - } + }, ); } - const doc = await didResolver.resolve( - body.repo as `did:${"plc" | "web"}:${string}` - ); - const pdsBaseURL = doc.service?.find( - (it) => it.id === "#atproto_pds" - )?.serviceEndpoint; - if (!pdsBaseURL || typeof pdsBaseURL !== "string") - return new Response(null, { status: 400 }); + const doc = await resolveDid(body.repo); + const pdsBaseURL = doc.service?.find(it => it.id === "#atproto_pds")?.serviceEndpoint; + if (!pdsBaseURL || typeof pdsBaseURL !== "string") return new Response(null, { status: 400 }); let filename: string = crypto.randomUUID(); diff --git a/client/viewer.tsx b/client/viewer.tsx index 9bc03ec..b95a049 100644 --- a/client/viewer.tsx +++ b/client/viewer.tsx @@ -9,13 +9,11 @@ import { XRPC } from "@char/lexicon.ts/rpc"; type VideoRecord = Infer; -const fetchVideoRecord = async ( - did: string, - rkey: string -): Promise => { +const fetchVideoRecord = async (did: string, rkey: string): Promise => { const didDoc = await resolveDid(did); - const pds = didDoc.service?.find((it) => it.id === "#atproto_pds") - ?.serviceEndpoint as string | undefined; + const pds = didDoc.service?.find(it => it.id === "#atproto_pds")?.serviceEndpoint as + | string + | undefined; if (!pds) throw new Error("could not resolve pds for requested repo"); @@ -32,10 +30,7 @@ const fetchVideoRecord = async ( return record.value as VideoRecord; }; -const resolveVideoURL = async ( - repo: `did:${string}`, - blob: string -): Promise => { +const resolveVideoURL = async (repo: `did:${string}`, blob: string): Promise => { try { const xrpc = new XRPC(globalThis.location.href); const res = await xrpc.call("blue.cerulea.video.fetchVideo", { @@ -63,7 +58,7 @@ const main = async () => { const record = await fetchVideoRecord(did, rkey); const videoURL = await resolveVideoURL( did, - "ref" in record.video ? record.video.ref.$link : record.video.cid + "ref" in record.video ? record.video.ref.$link : record.video.cid, ); const video = (