A decentralized music tracking and discovery platform built on AT Protocol 馃幍 rocksky.app
spotify atproto lastfm musicbrainz scrobbling listenbrainz
98
fork

Configure Feed

Select the types of activity you want to include in your feed.

at feat/pgpull 56 lines 1.5 kB view raw
1import { equals } from "@xata.io/client"; 2import { ctx } from "context"; 3import { eq } from "drizzle-orm"; 4import _ from "lodash"; 5import users from "schema/users"; 6 7const args = process.argv.slice(2); 8 9for (const did of args) { 10 const user = await ctx.client.db.users 11 .filter({ 12 $any: [{ did }, { handle: did }], 13 }) 14 .getFirst(); 15 if (!user) { 16 console.log(`User ${did} not found`); 17 continue; 18 } 19 20 const plc = await fetch(`https://plc.directory/${user.did}`).then((res) => 21 res.json() 22 ); 23 24 const serviceEndpoint = _.get(plc, "service.0.serviceEndpoint"); 25 if (!serviceEndpoint) { 26 console.log(`Service endpoint not found for ${did}`); 27 continue; 28 } 29 30 const profile = await fetch( 31 `${serviceEndpoint}/xrpc/com.atproto.repo.getRecord?repo=${user.did}&collection=app.bsky.actor.profile&rkey=self` 32 ).then((res) => res.json()); 33 const ref = _.get(profile, "value.avatar.ref.$link"); 34 const type = _.get(profile, "value.avatar.mimeType", "").split("/")[1]; 35 await ctx.db 36 .update(users) 37 .set({ 38 displayName: _.get(profile, "value.displayName"), 39 avatar: `https://cdn.bsky.app/img/avatar/plain/${user.did}/${ref}@${type}`, 40 }) 41 .where(eq(users.did, user.did)) 42 .execute(); 43 44 const u = await ctx.client.db.users 45 .select(["*"]) 46 .filter("did", equals(user.did)) 47 .getFirst(); 48 49 console.log(u); 50 51 ctx.nc.publish("rocksky.user", Buffer.from(JSON.stringify(u))); 52} 53 54console.log("Done"); 55 56process.exit(0);