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.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667import type { Agent } from "@atproto/api";import chalk from "chalk";import { consola } from "consola";import { ctx } from "context";import { eq } from "drizzle-orm";import { createAgent } from "lib/agent";import * as FeedGenerator from "lexicon/types/app/rocksky/feed/generator";import tables from "schema";import type { InsertFeed } from "schema/feeds";
const args = process.argv.slice(2);
if (args.length === 0) { consola.error("Please provide user author identifier (handle or DID)."); consola.info(`Usage: ${chalk.cyan("npm run seed:feed -- <handle|did>")}`); process.exit(1);}
async function getFeeds(agent: Agent, limit: number = 100) { const res = await agent.com.atproto.repo.listRecords({ repo: agent.assertDid, collection: "app.rocksky.feed.generator", limit, }); return res.data.records.map((record) => ({ ...record, value: FeedGenerator.isRecord(record.value) ? record.value : null, }));}
let userDid = args[0];
if (!userDid.startsWith("did:plc:") && !userDid.startsWith("did:web:")) { userDid = await ctx.baseIdResolver.handle.resolve(userDid);}
const agent = await createAgent(ctx.oauthClient, userDid);
const [user] = await ctx.db .select() .from(tables.users) .where(eq(tables.users.did, agent.assertDid)) .execute();
const feeds = await getFeeds(agent);
for (const feed of feeds) { if (!feed.value) continue;
await ctx.db .insert(tables.feeds) .values({ displayName: feed.value.displayName, description: feed.value.description, did: feed.value.did, userId: user.id, uri: feed.uri, } satisfies InsertFeed) .onConflictDoNothing() .execute(); consola.info( `Feed ${chalk.cyanBright(feed.value.displayName)} seeded successfully.`, );}
process.exit(0);