A decentralized music tracking and discovery platform built on AT Protocol 馃幍 rocksky.app
spotify atproto lastfm musicbrainz scrobbling listenbrainz
at feat/pgpull 66 lines 1.5 kB view raw
1import axios from "axios"; 2import useSWR from "swr"; 3import { API_URL } from "../consts"; 4 5function useChart() { 6 const fetcher = (path: string) => 7 fetch(`${API_URL}${path}`, { 8 method: "GET", 9 }).then((res) => res.json()); 10 11 const { data: scrobblesChart } = useSWR("/public/scrobbleschart", fetcher); 12 13 const getScrobblesChart = () => { 14 return scrobblesChart || []; 15 }; 16 17 const getSongChart = async (uri: string) => { 18 const response = await axios.get( 19 `${API_URL}/public/scrobbleschart?songuri=${uri}` 20 ); 21 if (response.status !== 200) { 22 return []; 23 } 24 return response.data; 25 }; 26 27 const getArtistChart = async (uri: string) => { 28 const response = await axios.get( 29 `${API_URL}/public/scrobbleschart?artisturi=${uri}` 30 ); 31 if (response.status !== 200) { 32 return []; 33 } 34 return response.data; 35 }; 36 37 const getAlbumChart = async (uri: string) => { 38 const response = await axios.get( 39 `${API_URL}/public/scrobbleschart?albumuri=${uri}` 40 ); 41 if (response.status !== 200) { 42 return []; 43 } 44 return response.data; 45 }; 46 47 const getProfileChart = async (did: string) => { 48 const response = await axios.get( 49 `${API_URL}/public/scrobbleschart?did=${did}` 50 ); 51 if (response.status !== 200) { 52 return []; 53 } 54 return response.data; 55 }; 56 57 return { 58 getScrobblesChart, 59 getSongChart, 60 getArtistChart, 61 getAlbumChart, 62 getProfileChart, 63 }; 64} 65 66export default useChart;