Something went wrong. Try again.
A decentralized music tracking and discovery platform built on AT Protocol 🎵 rocksky.app
spotify atproto lastfm musicbrainz scrobbling listenbrainz
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536import chalk from "chalk";import { consola } from "consola";import type { Context } from "context";import { eq } from "drizzle-orm";import _ from "lodash";import { StringCodec } from "nats";import tables from "schema";import { indexUsers } from "typesense/search";
export function onNewUser(ctx: Context) { const sc = StringCodec(); const sub = ctx.nc.subscribe("rocksky.user"); (async () => { for await (const m of sub) { try { const payload: { xata_id: string; } = JSON.parse(sc.decode(m.data)); const results = await ctx.db .select() .from(tables.users) .where(eq(tables.users.id, payload.xata_id)) .execute();
consola.info(`New user: ${chalk.cyan(_.get(results, "0.handle"))}`);
await indexUsers(results).catch((e) => consola.warn("[typesense] index failed:", e), ); } catch (e) { consola.error("rocksky.user handler error:", e); } } })().catch((e) => consola.error("rocksky.user subscriber crashed:", e));}