Files
swingmusic-extended/src/composables/fetch/artists.ts
T
2023-01-13 18:13:49 +03:00

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 };