A decentralized music tracking and discovery platform built on AT Protocol 🎵
0
fork

Configure Feed

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

feat: implement deduplication script for scrobble records

+50 -1
+2 -1
apps/api/package.json
··· 24 24 "prod:all": "concurrently 'tsx ./src/index.ts' 'tsx ./src/server.ts'", 25 25 "format": "biome format src", 26 26 "lint": "biome lint src", 27 - "feed": "tsx ./src/scripts/feed.ts" 27 + "feed": "tsx ./src/scripts/feed.ts", 28 + "dedup": "tsx ./src/scripts/dedup.ts" 28 29 }, 29 30 "dependencies": { 30 31 "@atproto/api": "^0.13.31",
+48
apps/api/src/scripts/dedup.ts
··· 1 + import chalk from "chalk"; 2 + import { ctx } from "context"; 3 + import { eq } from "drizzle-orm"; 4 + import { createAgent } from "lib/agent"; 5 + import tables from "schema"; 6 + 7 + const args = process.argv.slice(2); 8 + 9 + if (args.length === 0) { 10 + console.error("Please provide user author identifier (handle or DID)."); 11 + console.log(`Usage: ${chalk.cyan("npm run feed -- <handle|did>")}`); 12 + process.exit(1); 13 + } 14 + 15 + let did = args[0]; 16 + 17 + if (!did.startsWith("did:plc:")) { 18 + did = await ctx.baseIdResolver.handle.resolve(did); 19 + } 20 + 21 + const agent = await createAgent(ctx.oauthClient, did); 22 + const records = await agent.com.atproto.repo.listRecords({ 23 + repo: agent.assertDid, 24 + collection: "app.rocksky.scrobble", 25 + limit: 100, 26 + }); 27 + 28 + for (const record of records.data.records) { 29 + const result = await ctx.db 30 + .select() 31 + .from(tables.scrobbles) 32 + .where(eq(tables.scrobbles.uri, record.uri)) 33 + .limit(1); 34 + if (result.length === 0) { 35 + console.log(`Deleting record ${record.rkey}...`); 36 + console.log("deleting record:"); 37 + console.log(record); 38 + /*await agent.com.atproto.repo.deleteRecord({ 39 + repo: agent.assertDid, 40 + collection: "app.rocksky.scrobble", 41 + rkey: record.rkey, 42 + }); 43 + */ 44 + } else { 45 + console.log(`Keeping record:`); 46 + console.log(record); 47 + } 48 + }