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

Include artist picture and genres in song match

+46 -4
+46 -4
apps/api/src/xrpc/app/rocksky/song/matchSong.ts
··· 37 37 const retrieve = ({ params, ctx }: { params: QueryParams; ctx: Context }) => { 38 38 return Effect.tryPromise({ 39 39 try: async () => { 40 - let track = await ctx.db 40 + let record = await ctx.db 41 41 .select() 42 42 .from(tables.tracks) 43 + .leftJoin( 44 + tables.albumTracks, 45 + eq(tables.albumTracks.trackId, tables.tracks.id), 46 + ) 47 + .leftJoin( 48 + tables.albums, 49 + eq(tables.albumTracks.albumId, tables.albums.id), 50 + ) 51 + .leftJoin( 52 + tables.artistAlbums, 53 + eq(tables.artistAlbums.albumId, tables.albums.id), 54 + ) 55 + .leftJoin( 56 + tables.artists, 57 + eq(tables.artistAlbums.artistId, tables.artists.id), 58 + ) 43 59 .where( 44 60 or( 45 61 and( ··· 55 71 .execute() 56 72 .then(([row]) => row); 57 73 74 + let track = record?.tracks; 75 + 58 76 let releaseDate = null, 59 - year = null; 77 + year = null, 78 + artistPicture = null, 79 + genres = null; 60 80 61 - if (!track) { 81 + if (!record) { 62 82 const spotifyTrack = await searchOnSpotify( 63 83 ctx, 64 84 params.title, ··· 105 125 releaseDate = `${spotifyTrack.album.release_date}-01-01`; 106 126 year = parseInt(spotifyTrack.album.release_date); 107 127 } 128 + 129 + artistPicture = spotifyTrack.artists[0]?.images?.[0]?.url || null; 130 + genres = spotifyTrack.artists[0]?.genres || null; 108 131 } 132 + } else { 133 + artistPicture = record.artists.picture; 134 + genres = record.artists.genres; 135 + releaseDate = record.albums.releaseDate; 136 + year = record.albums.year; 109 137 } 110 138 111 139 return Promise.all([ ··· 126 154 .then((rows) => rows[0]?.count || 0), 127 155 Promise.resolve(releaseDate), 128 156 Promise.resolve(year), 157 + Promise.resolve(artistPicture), 158 + Promise.resolve(genres), 129 159 ]); 130 160 }, 131 161 catch: (error) => new Error(`Failed to retrieve artist: ${error}`), 132 162 }); 133 163 }; 134 164 135 - const presentation = ([track, uniqueListeners, playCount, releaseDate, year]: [ 165 + const presentation = ([ 166 + track, 167 + uniqueListeners, 168 + playCount, 169 + releaseDate, 170 + year, 171 + artistPicture, 172 + genres, 173 + ]: [ 136 174 SelectTrack, 137 175 number, 138 176 number, 139 177 string | null, 140 178 number | null, 179 + string | null, 180 + string[] | null, 141 181 ]): Effect.Effect<SongViewDetailed, never> => { 142 182 return Effect.sync(() => ({ 143 183 ...track, 144 184 releaseDate, 145 185 year, 186 + artistPicture, 187 + genres, 146 188 playCount, 147 189 uniqueListeners, 148 190 createdAt: track.createdAt.toISOString(),