A couple of Bluesky feeds focused around PDSes

Get cached pds first in feedgen

Changed files
+20 -13
+20 -13
feedgen.ts
··· 23 23 import type { Statement } from "@db/sqlite"; 24 24 25 25 import { db } from "./common/db.ts"; 26 - import type { DID, Post } from "./common/types.ts"; 26 + import type { Author, DID, Post } from "./common/types.ts"; 27 27 28 28 const publisher = Deno.env.get("PUBLISHER") ?? "did:example:bob"; 29 29 const hostname = Deno.env.get("HOSTNAME"); ··· 112 112 return result.value; 113 113 }; 114 114 115 + const getAuthor = db.prepare("SELECT pds FROM authors WHERE did = ?"); 116 + 115 117 app.add(AppBskyFeedGetFeedSkeleton.mainSchema, { 116 118 async handler({ request, params: { feed, limit, cursor } }) { 117 119 const feedUri = parseResourceUri(feed); ··· 137 139 if (feedQuery.pds) { 138 140 const jwt = await requireAuth(request, "app.bsky.feed.getFeedSkeleton"); 139 141 140 - const resolved = await didResolver.resolve(jwt.issuer as DID); 141 - for (const service of resolved.service ?? []) { 142 - if ( 143 - service.type == "AtprotoPersonalDataServer" && 144 - typeof service.serviceEndpoint === "string" 145 - ) { 146 - pds = service.serviceEndpoint; 142 + const author = getAuthor.get<Author>(jwt.issuer); 143 + if (author) { 144 + pds = author.pds; 145 + } else { 146 + const resolved = await didResolver.resolve(jwt.issuer as DID); 147 + for (const service of resolved.service ?? []) { 148 + if ( 149 + service.type == "AtprotoPersonalDataServer" && 150 + typeof service.serviceEndpoint === "string" 151 + ) { 152 + pds = service.serviceEndpoint; 153 + } 147 154 } 155 + if (typeof pds !== "string") 156 + throw new InvalidRequestError({ 157 + error: "NoServiceEndpoint", 158 + description: "No service endpoint", 159 + }); 148 160 } 149 - if (typeof pds !== "string") 150 - throw new InvalidRequestError({ 151 - error: "NoServiceEndpoint", 152 - description: "No service endpoint", 153 - }); 154 161 } 155 162 156 163 let res: Post[];