Spark feed generator template
1import { AuthRequiredError, InvalidRequestError } from "@atp/xrpc-server";
2import { Server } from "../lex/index.ts";
3import { getAlgo } from "../algos/index.ts";
4import { AppContext } from "../main.ts";
5import { AtUri } from "@atp/syntax";
6
7export default function (server: Server, ctx: AppContext) {
8 server.so.sprk.feed.getFeedSkeleton({
9 auth: ctx.authVerifier.standardOptional,
10 handler: async ({ params, auth }) => {
11 const feedUri = new AtUri(params.feed);
12 const algo = getAlgo(feedUri.hostname, feedUri.rkey);
13 if (
14 feedUri.collection !== "so.sprk.feed.generator" ||
15 !algo
16 ) {
17 throw new InvalidRequestError(
18 "Unsupported algorithm",
19 "UnsupportedAlgorithm",
20 );
21 }
22 const did = auth.credentials.type === "standard"
23 ? auth.credentials.iss
24 : null;
25 if (algo.needsAuth && !did) {
26 throw new AuthRequiredError();
27 }
28
29 const body = await algo.handler(ctx, params, did);
30 return {
31 encoding: "application/json",
32 body: body,
33 };
34 },
35 });
36}