A decentralized music tracking and discovery platform built on AT Protocol 馃幍 rocksky.app
spotify atproto lastfm musicbrainz scrobbling listenbrainz
at feat/pgpull 39 lines 1.1 kB view raw
1import { RockskyClient } from "client"; 2import dayjs from "dayjs"; 3import relative from "dayjs/plugin/relativeTime.js"; 4 5dayjs.extend(relative); 6 7export async function scrobbles(did, { skip, limit }): Promise<string> { 8 try { 9 const client = new RockskyClient(); 10 const scrobbles = await client.scrobbles(did, { skip, limit }); 11 12 if (did) { 13 return JSON.stringify( 14 scrobbles.map((scrobble) => ({ 15 title: scrobble.title, 16 artist: scrobble.artist, 17 date: dayjs(scrobble.created_at + "Z").fromNow(), 18 isoDate: scrobble.created_at, 19 })), 20 null, 21 2 22 ); 23 } 24 25 return JSON.stringify( 26 scrobbles.map((scrobble) => ({ 27 user: `@${scrobble.user}`, 28 title: scrobble.title, 29 artist: scrobble.artist, 30 date: dayjs(scrobble.date).fromNow(), 31 isoDate: scrobble.date, 32 })), 33 null, 34 2 35 ); 36 } catch (err) { 37 return `Failed to fetch scrobbles data. Please check your token and try again, error: ${err.message}`; 38 } 39}