[READ ONLY MIRROR] Spark Social AppView Server github.com/sprksocial/server
atproto deno hono lexicon
1
fork

Configure Feed

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

at main 72 lines 1.9 kB view raw
1import type { 2 ModServiceOutput, 3 NullOutput, 4 RoleOutput, 5 StandardOutput, 6} from "../auth-verifier.ts"; 7import type { AppContext } from "../context.ts"; 8import type { HydrateCtx, HydrateCtxVals } from "../hydration/index.ts"; 9import { formatLabelerHeader, ParsedLabelers } from "../util.ts"; 10 11export const SPRK_USER_AGENT = "SprkAppView"; 12export const ATPROTO_CONTENT_LABELERS = "Atproto-Content-Labelers"; 13export const ATPROTO_REPO_REV = "Atproto-Repo-Rev"; 14 15type ResHeaderOpts = { 16 labelers: ParsedLabelers; 17 repoRev: string | null; 18}; 19 20export const resHeaders = ( 21 opts: Partial<ResHeaderOpts>, 22): Record<string, string> => { 23 const headers: Record<string, string> = {}; 24 if (opts.labelers) { 25 headers[ATPROTO_CONTENT_LABELERS] = formatLabelerHeader(opts.labelers); 26 } 27 if (opts.repoRev) { 28 headers[ATPROTO_REPO_REV] = opts.repoRev; 29 } 30 return headers; 31}; 32 33export const clearlyBadCursor = (cursor?: string) => { 34 return !!cursor?.includes("::"); 35}; 36 37type HydrateCtxAuth = 38 | StandardOutput 39 | RoleOutput 40 | NullOutput 41 | ModServiceOutput; 42 43export const createHydrateCtxFromAuth = ( 44 ctx: AppContext, 45 req: Request, 46 auth: HydrateCtxAuth, 47 overrides: Partial<HydrateCtxVals> = {}, 48): Promise<HydrateCtx> => { 49 const labelers = ctx.reqLabelers(req); 50 const { canPerformTakedown: _canPerformTakedown, ...hydrateVals } = ctx 51 .authVerifier.parseCreds(auth); 52 53 return ctx.hydrator.createContext({ 54 labelers, 55 ...hydrateVals, 56 ...overrides, 57 }); 58}; 59 60export const getThreadDepth = (opts: { 61 anchor: string; 62 depth: number; 63 maxThreadDepth?: number; 64 bigThreadUris: Set<string>; 65 bigThreadDepth?: number; 66}): number => { 67 let max = opts.maxThreadDepth; 68 if (opts.bigThreadUris.has(opts.anchor) && opts.bigThreadDepth) { 69 max = opts.bigThreadDepth; 70 } 71 return max ? Math.min(max, opts.depth) : opts.depth; 72};