mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 12:33:03 +00:00
56 lines
1.1 KiB
TypeScript
56 lines
1.1 KiB
TypeScript
import { paths } from "@/config";
|
|
import useAxios from "./useAxios";
|
|
import { Artist, Track, Album } from "@/interfaces";
|
|
|
|
const getArtistData = async (hash: string) => {
|
|
interface ArtistData {
|
|
artist: Artist;
|
|
tracks: Track[];
|
|
}
|
|
|
|
const { data, error } = await useAxios({
|
|
get: true,
|
|
url: paths.api.artist + `/${hash}`,
|
|
});
|
|
|
|
if (error) {
|
|
console.error(error);
|
|
}
|
|
|
|
return data as ArtistData;
|
|
};
|
|
|
|
const getArtistAlbums = async (hash: string, limit = 6) => {
|
|
interface ArtistAlbums {
|
|
albums: Album[];
|
|
eps: Album[];
|
|
singles: Album[];
|
|
}
|
|
|
|
const { data, error } = await useAxios({
|
|
get: true,
|
|
url: paths.api.artist + `/${hash}/albums?limit=${limit}`,
|
|
});
|
|
|
|
if (error) {
|
|
console.error(error);
|
|
}
|
|
|
|
return data as ArtistAlbums;
|
|
};
|
|
|
|
const getArtistTracks = async (hash: string, offset: number = 0, limit = 6) => {
|
|
const { data, error } = await useAxios({
|
|
get: true,
|
|
url: paths.api.artist + `/${hash}/tracks?offset=${offset}&limit=${limit}`,
|
|
});
|
|
|
|
if (error) {
|
|
console.error(error);
|
|
}
|
|
|
|
return data.tracks as Track[];
|
|
};
|
|
|
|
export { getArtistData, getArtistAlbums, getArtistTracks };
|