restar
uses tcmts.server.request, which uses tcmts.server.requestNow, which uses tcmts.server.callNow, which uses #tcm/host (call)
Called by a visitor's browser once it's starred a library, or taken a star back: checked against their repository at once, rather than when Jetstream says so. The library's stars now, and whether theirs is among them. Anyone can call it, so it takes DIDs alone (no star elsewhere can be made to count), and a few calls a minute from each address.
import { isDid } from "#codebase/tcmts/atproto"; import { STAR_COLLECTION, starKey } from "#codebase/tcmts/records"; import { checkStar, libraryKey, starCounts } from "#codebase/tcmts/registry"; import { HttpError, rateLimit, request } from "#codebase/tcmts/server"; export async function restar( did: string, author: string, pkg: string, ): Promise<{ count: number; starred: boolean }> { if (!isDid(did) || !isDid(author) || !pkg || pkg.length > 214) throw new HttpError(400, "a star is a DID's, of a library: its author's DID and its package"); const ip = (() => { try { return request().ip; } catch { return undefined; } })(); if (ip !== undefined) rateLimit(`restar:${ip}`, { max: 30, per: 60 }); const starred = await checkStar(`at://${did}/${STAR_COLLECTION}/${starKey(author, pkg)}`); return { count: (await starCounts()).get(libraryKey({ did: author, package: pkg })) ?? 0, starred, }; }
uses
- tcmts.atproto.isDid
- tcmts.records.STAR_COLLECTION
- tcmts.records.starKey
- tcmts.registry.checkStar
- tcmts.registry.libraryKey
- tcmts.registry.starCounts
- tcmts.server.HttpError
- tcmts.server.rateLimit
- tcmts.server.request