A decentralized music tracking and discovery platform built on AT Protocol 馃幍
at feat/like-scrobble 113 lines 2.8 kB view raw
1import { client } from "."; 2 3export const getFeedByUri = async (uri: string) => { 4 if (uri.includes("app.rocksky.song")) { 5 return null; 6 } 7 const response = await client.get("/xrpc/app.rocksky.scrobble.getScrobble", { 8 params: { uri }, 9 }); 10 11 if (response.status !== 200) { 12 return null; 13 } 14 15 return { 16 id: response.data?.id, 17 title: response.data?.title, 18 artist: response.data?.artist, 19 albumArtist: response.data?.albumArtist, 20 album: response.data?.album, 21 cover: response.data?.cover, 22 tags: [], 23 artistUri: response.data?.artistUri, 24 albumUri: response.data?.albumUri, 25 listeners: response.data?.listeners || 1, 26 scrobbles: response.data?.scrobbles || 1, 27 lyrics: response.data?.lyrics, 28 spotifyLink: response.data?.spotifyLink, 29 composer: response.data?.composer, 30 uri: response.data?.uri, 31 }; 32}; 33 34export const getFeedGenerators = async () => { 35 const response = await client.get<{ 36 feeds: { 37 id: string; 38 name: string; 39 uri: string; 40 description: string; 41 did: string; 42 avatar?: string; 43 creator: { 44 avatar?: string; 45 displayName: string; 46 handle: string; 47 did: string; 48 id: string; 49 }; 50 }[]; 51 }>("/xrpc/app.rocksky.feed.getFeedGenerators"); 52 if (response.status !== 200) { 53 return null; 54 } 55 return response.data; 56}; 57 58export const getFeed = async (uri: string, limit?: number, cursor?: string) => { 59 const response = await client.get<{ 60 feed: { 61 scrobble: { 62 title: string; 63 artist: string; 64 albumArtist: string; 65 album: string; 66 trackNumber: number; 67 duration: number; 68 mbId: string | null; 69 youtubeLink: string | null; 70 spotifyLink: string | null; 71 appleMusicLink: string | null; 72 tidalLink: string | null; 73 sha256: string; 74 discNumber: number; 75 composer: string | null; 76 genre: string | null; 77 label: string | null; 78 copyrightMessage: string | null; 79 uri: string; 80 albumUri: string; 81 artistUri: string; 82 trackUri: string; 83 xataVersion: number; 84 cover: string; 85 date: string; 86 user: string; 87 userDisplayName: string; 88 userAvatar: string; 89 tags: string[]; 90 likesCount: number; 91 liked: boolean; 92 id: string; 93 }; 94 }[]; 95 }>("/xrpc/app.rocksky.feed.getFeed", { 96 params: { 97 feed: uri, 98 limit, 99 cursor, 100 }, 101 headers: { 102 Authorization: localStorage.getItem("token") 103 ? `Bearer ${localStorage.getItem("token")}` 104 : undefined, 105 }, 106 }); 107 108 if (response.status !== 200) { 109 return []; 110 } 111 112 return response.data.feed.map(({ scrobble }) => scrobble); 113};