forked from
rocksky.app/rocksky
A decentralized music tracking and discovery platform built on AT Protocol 馃幍
1import axios from "axios";
2import { API_URL } from "../consts";
3
4export const getSongByUri = async (uri: string) => {
5 const response = await axios.get(`${API_URL}/users/${uri}`);
6 return {
7 id: response.data?.id,
8 title: response.data?.title,
9 artist: response.data?.artist,
10 albumArtist: response.data?.album_artist,
11 album: response.data?.album,
12 cover: response.data?.album_art,
13 tags: [],
14 artistUri: response.data?.artist_uri,
15 albumUri: response.data?.album_uri,
16 listeners: response.data?.listeners || 1,
17 scrobbles: response.data?.scrobbles || 1,
18 lyrics: response.data?.lyrics,
19 spotifyLink: response.data?.spotify_link,
20 composer: response.data?.composer,
21 uri: response.data?.uri,
22 };
23};
24
25export const getArtistTracks = async (
26 uri: string,
27 limit = 10,
28): Promise<
29 {
30 id: string;
31 title: string;
32 artist: string;
33 album_artist: string;
34 album_art: string;
35 uri: string;
36 play_count: number;
37 album_uri?: string;
38 artist_uri?: string;
39 }[]
40> => {
41 const response = await axios.get(
42 `${API_URL}/users/${uri}/tracks?size=${limit}`,
43 );
44 return response.data;
45};
46
47export const getArtistAlbums = async (
48 uri: string,
49 limit = 10,
50): Promise<
51 {
52 id: string;
53 title: string;
54 artist: string;
55 album_art: string;
56 artist_uri: string;
57 uri: string;
58 }[]
59> => {
60 const response = await axios.get(
61 `${API_URL}/users/${uri}/albums?size=${limit}`,
62 );
63 return response.data;
64};
65
66export const getArtists = async (did: string, offset = 0, limit = 30) => {
67 const response = await axios.get(
68 `${API_URL}/users/${did}/artists?size=${limit}&offset=${offset}`,
69 );
70 // eslint-disable-next-line @typescript-eslint/no-explicit-any
71 return response.data.map((x: any) => ({ ...x, scrobbles: x.play_count }));
72};
73
74export const getAlbums = async (did: string, offset = 0, limit = 12) => {
75 const response = await axios.get(
76 `${API_URL}/users/${did}/albums?size=${limit}&offset=${offset}`,
77 );
78 // eslint-disable-next-line @typescript-eslint/no-explicit-any
79 return response.data.map((x: any) => ({
80 ...x,
81 scrobbles: x.play_count,
82 }));
83};
84
85export const getTracks = async (did: string, offset = 0, limit = 20) => {
86 const response = await axios.get(
87 `${API_URL}/users/${did}/tracks?size=${limit}&offset=${offset}`,
88 );
89 // eslint-disable-next-line @typescript-eslint/no-explicit-any
90 return response.data.map((x: any) => ({ ...x, scrobbles: x.play_count }));
91};
92
93export const getLovedTracks = async (did: string, offset = 0, limit = 20) => {
94 const response = await axios.get(
95 `${API_URL}/users/${did}/likes?size=${limit}&offset=${offset}`,
96 );
97 return response.data;
98};
99
100export const getAlbum = async (did: string, rkey: string) => {
101 const response = await axios.get(
102 `${API_URL}/users/${did}/app.rocksky.album/${rkey}`,
103 );
104 return response.data;
105};
106
107export const getArtist = async (did: string, rkey: string) => {
108 const response = await axios.get(
109 `${API_URL}/users/${did}/app.rocksky.artist/${rkey}`,
110 );
111 return response.data;
112};