A decentralized music tracking and discovery platform built on AT Protocol 馃幍
at main 32 lines 1.1 kB view raw
1import { AuthRequiredError, InvalidRequestError } from "@atp/xrpc-server"; 2import { Server } from "../lex/index.ts"; 3import { getAlgo } from "../algos/mod.ts"; 4import { Context } from "../context.ts"; 5import { AtUri } from "@atp/syntax"; 6 7export default function (server: Server, ctx: Context) { 8 server.app.rocksky.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 (feedUri.collection !== "app.rocksky.feed.generator" || !algo) { 14 throw new InvalidRequestError( 15 "Unsupported algorithm", 16 "UnsupportedAlgorithm", 17 ); 18 } 19 const did = 20 auth.credentials.type === "standard" ? auth.credentials.iss : null; 21 if (algo.needsAuth && !did) { 22 throw new AuthRequiredError(); 23 } 24 25 const body = await algo.handler(ctx, params, did); 26 return { 27 encoding: "application/json", 28 body: body, 29 }; 30 }, 31 }); 32}