mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 12:33:03 +00:00
6efbb47166
- 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
64 lines
1.2 KiB
JavaScript
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,
|
|
};
|