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.

log collections script errors

fix collections script

fix collections script

fix collections script

fix collections script

+37 -13
+37 -13
apps/api/src/scripts/collections.ts
··· 195 195 [newScrobble] = await ctx.db 196 196 .select() 197 197 .from(schema.scrobbles) 198 - .where(eq(schema.scrobbles.uri, scrobble.uri)) 198 + .where( 199 + or( 200 + and( 201 + eq(schema.scrobbles.userId, user.id), 202 + eq(schema.scrobbles.trackId, track.id), 203 + eq(schema.scrobbles.artistId, artist.id), 204 + eq(schema.scrobbles.timestamp, new Date(value.createdAt)), 205 + ), 206 + eq(schema.scrobbles.uri, scrobble.uri), 207 + ), 208 + ) 199 209 .limit(1) 200 210 .execute(); 201 211 } ··· 222 232 } 223 233 await publishScrobble(ctx, newScrobble.id); 224 234 } catch (err) { 225 - consola.error( 226 - `Failed to sync scrobble ${chalk.cyan(newScrobble.id)}:`, 227 - err, 228 - ); 235 + consola.error(`Failed to sync scrobble:`, err); 229 236 } 230 237 }), 231 238 ); ··· 347 354 .insert(schema.albumTracks) 348 355 .values({ 349 356 albumId: album.id, 357 + trackId: newTrack.id, 358 + }) 359 + .onConflictDoNothing() 360 + .execute(), 361 + ctx.db 362 + .insert(schema.artistTracks) 363 + .values({ 364 + artistId: artist.id, 350 365 trackId: newTrack.id, 351 366 }) 352 367 .onConflictDoNothing() ··· 430 445 .update(`${value.title} - ${value.artist}`.toLowerCase()) 431 446 .digest("hex"); 432 447 448 + const [artist] = await ctx.db 449 + .select() 450 + .from(schema.artists) 451 + .where(eq(schema.artists.name, value.artist)) 452 + .limit(1) 453 + .execute(); 454 + 433 455 let [newAlbum] = await ctx.db 434 456 .insert(schema.albums) 435 457 .values({ ··· 437 459 artist: value.artist, 438 460 uri: album.uri, 439 461 albumArt: value.albumArtUrl, 462 + artistUri: artist.uri, 440 463 sha256, 441 464 year: value.year, 442 465 releaseDate: value.releaseDate, 443 466 }) 444 - .onConflictDoNothing() 467 + .onConflictDoUpdate({ 468 + target: schema.albums.sha256, 469 + set: { 470 + albumArt: value.albumArtUrl, 471 + artistUri: artist.uri, 472 + year: value.year, 473 + releaseDate: value.releaseDate, 474 + }, 475 + }) 445 476 .returning() 446 477 .execute(); 447 478 ··· 454 485 .execute(); 455 486 newAlbum = existingAlbum; 456 487 } 457 - 458 - const [artist] = await ctx.db 459 - .select() 460 - .from(schema.artists) 461 - .where(eq(schema.artists.name, value.artist)) 462 - .limit(1) 463 - .execute(); 464 488 465 489 await Promise.all([ 466 490 ctx.db