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

Add album data retrieval to scrobble presentation

+9 -5
+9 -5
apps/api/src/xrpc/app/rocksky/scrobble/getScrobble.ts
··· 6 import type { QueryParams } from "lexicon/types/app/rocksky/scrobble/getScrobble"; 7 import * as R from "ramda"; 8 import tables from "schema"; 9 import type { SelectScrobble } from "schema/scrobbles"; 10 import type { SelectTrack } from "schema/tracks"; 11 import type { SelectUser } from "schema/users"; ··· 21 Effect.catchAll((err) => { 22 console.error("Error retrieving scrobble:", err); 23 return Effect.succeed({}); 24 - }), 25 ); 26 server.app.rocksky.scrobble.getScrobble({ 27 handler: async ({ params }) => { ··· 48 .from(tables.scrobbles) 49 .leftJoin(tables.tracks, eq(tables.scrobbles.trackId, tables.tracks.id)) 50 .leftJoin(tables.users, eq(tables.scrobbles.userId, tables.users.id)) 51 .where(eq(tables.scrobbles.uri, params.uri)) 52 .execute() 53 .then((rows) => rows[0]); ··· 61 .from(tables.scrobbles) 62 .leftJoin( 63 tables.tracks, 64 - eq(tables.tracks.id, tables.scrobbles.trackId), 65 ) 66 .leftJoin(tables.users, eq(tables.scrobbles.userId, tables.users.id)) 67 .where(eq(tables.scrobbles.trackId, scrobble?.tracks.id)) ··· 73 .from(tables.scrobbles) 74 .leftJoin( 75 tables.tracks, 76 - eq(tables.scrobbles.trackId, tables.tracks.id), 77 ) 78 .where(eq(tables.scrobbles.trackId, scrobble?.tracks.id)) 79 .execute() ··· 85 }; 86 87 const presentation = ([ 88 - { scrobbles, tracks, users }, 89 listeners, 90 scrobblesCount, 91 ]: [Scrobble | undefined, number, number]): Effect.Effect< ··· 93 never 94 > => { 95 return Effect.sync(() => ({ 96 - ...R.omit(["albumArt", "id"], tracks), 97 cover: tracks.albumArt, 98 date: scrobbles.timestamp.toISOString(), 99 user: users.handle, ··· 109 scrobbles: SelectScrobble; 110 tracks: SelectTrack; 111 users: SelectUser; 112 };
··· 6 import type { QueryParams } from "lexicon/types/app/rocksky/scrobble/getScrobble"; 7 import * as R from "ramda"; 8 import tables from "schema"; 9 + import { SelectAlbum } from "schema/albums"; 10 import type { SelectScrobble } from "schema/scrobbles"; 11 import type { SelectTrack } from "schema/tracks"; 12 import type { SelectUser } from "schema/users"; ··· 22 Effect.catchAll((err) => { 23 console.error("Error retrieving scrobble:", err); 24 return Effect.succeed({}); 25 + }) 26 ); 27 server.app.rocksky.scrobble.getScrobble({ 28 handler: async ({ params }) => { ··· 49 .from(tables.scrobbles) 50 .leftJoin(tables.tracks, eq(tables.scrobbles.trackId, tables.tracks.id)) 51 .leftJoin(tables.users, eq(tables.scrobbles.userId, tables.users.id)) 52 + .leftJoin(tables.albums, eq(tables.scrobbles.albumId, tables.albums.id)) 53 .where(eq(tables.scrobbles.uri, params.uri)) 54 .execute() 55 .then((rows) => rows[0]); ··· 63 .from(tables.scrobbles) 64 .leftJoin( 65 tables.tracks, 66 + eq(tables.tracks.id, tables.scrobbles.trackId) 67 ) 68 .leftJoin(tables.users, eq(tables.scrobbles.userId, tables.users.id)) 69 .where(eq(tables.scrobbles.trackId, scrobble?.tracks.id)) ··· 75 .from(tables.scrobbles) 76 .leftJoin( 77 tables.tracks, 78 + eq(tables.scrobbles.trackId, tables.tracks.id) 79 ) 80 .where(eq(tables.scrobbles.trackId, scrobble?.tracks.id)) 81 .execute() ··· 87 }; 88 89 const presentation = ([ 90 + { scrobbles, tracks, users, albums }, 91 listeners, 92 scrobblesCount, 93 ]: [Scrobble | undefined, number, number]): Effect.Effect< ··· 95 never 96 > => { 97 return Effect.sync(() => ({ 98 + ...R.omit(["albumArt", "id", "albumUri"], tracks), 99 + albumUri: albums.uri, 100 cover: tracks.albumArt, 101 date: scrobbles.timestamp.toISOString(), 102 user: users.handle, ··· 112 scrobbles: SelectScrobble; 113 tracks: SelectTrack; 114 users: SelectUser; 115 + albums: SelectAlbum; 116 };