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

[api] add sync library script

+10 -13
+10 -13
apps/api/src/scripts/sync-library.ts
··· 1 1 import chalk from "chalk"; 2 2 import { ctx } from "context"; 3 - import { and, count, eq, not } from "drizzle-orm"; 3 + import { and, count, eq } from "drizzle-orm"; 4 4 import tables from "schema"; 5 5 import { InsertArtistAlbum } from "schema/artist-albums"; 6 6 ··· 8 8 const total = await ctx.db 9 9 .select({ value: count() }) 10 10 .from(tables.tracks) 11 - .where( 12 - and( 13 - not(eq(tables.tracks.albumUri, null)), 14 - not(eq(tables.tracks.artistUri, null)) 15 - ) 16 - ) 17 11 .execute() 18 12 .then(([row]) => row.value); 19 13 ··· 27 21 const results = await ctx.db 28 22 .select() 29 23 .from(tables.tracks) 30 - .where( 31 - and( 32 - not(eq(tables.tracks.albumUri, null)), 33 - not(eq(tables.tracks.artistUri, null)) 34 - ) 35 - ) 36 24 .limit(size) 37 25 .offset(skip) 38 26 .execute(); 39 27 40 28 for (const track of results) { 29 + if (!track.artistUri || !track.albumUri) { 30 + console.log( 31 + `Skipping track ${chalk.cyan(track.title)} due to missing artist or album URI` 32 + ); 33 + console.log("artistUri", track.artistUri); 34 + console.log("albumUri", track.albumUri); 35 + continue; 36 + } 37 + 41 38 const found = await ctx.db 42 39 .select() 43 40 .from(tables.artistAlbums)