Files
swingmusic-extended/src/composables/album.js
T
geoffrey45 6efbb47166 some bug fixes
- watch route params instead of route object in folderview
- move to script setup on album view
- use album as a reactive object instead of refs
- use axios instead of fetch to get album data
- improve clickable areas on songItem
- move album requests to POST
2022-03-01 19:46:37 +03:00

64 lines
1.2 KiB
JavaScript

import axios from "axios";
import state from "./state";
const getAlbumTracks = async (album, artist) => {
let data = {};
await axios
.post(state.settings.uri + "/album/tracks", {
album: album,
artist: artist,
})
.then((res) => {
data = res.data;
})
.catch((err) => {
console.error(err);
});
return data;
};
const getAlbumArtists = async (album, artist) => {
let artists = [];
await axios
.post(state.settings.uri + "/album/artists", {
album: album,
artist: artist,
})
.then((res) => {
artists = res.data.artists;
})
.catch((err) => {
console.error(err);
});
return artists;
};
const getAlbumBio = async (name, artist) => {
const res = await fetch(
state.settings.uri +
"/album/" +
encodeURIComponent(name.replaceAll("/", "|")) +
"/" +
encodeURIComponent(artist.replaceAll("/", "|")) +
"/bio"
);
if (!res.ok) {
const message = `An error has occurred: ${res.status}`;
throw new Error(message);
}
const data = await res.json();
return data.bio;
};
export default {
getAlbumTracks,
getAlbumArtists,
getAlbumBio,
};