use album hash to resolve album page

This commit is contained in:
geoffrey45
2022-06-26 19:05:36 +03:00
parent 92ef22596b
commit 22ff52e86e
9 changed files with 36 additions and 48 deletions
+6 -6
View File
@@ -40,8 +40,7 @@ def get_albums():
def get_album(): def get_album():
"""Returns all the tracks in the given album.""" """Returns all the tracks in the given album."""
data = request.get_json() data = request.get_json()
album, artist = data["album"], data["artist"] albumhash = data["hash"]
albumhash = helpers.create_album_hash(album, artist)
tracks = instances.tracks_instance.find_tracks_by_hash(albumhash) tracks = instances.tracks_instance.find_tracks_by_hash(albumhash)
tracks = [models.Track(t) for t in tracks] tracks = [models.Track(t) for t in tracks]
@@ -72,8 +71,10 @@ def get_album():
def get_album_bio(): def get_album_bio():
"""Returns the album bio for the given album.""" """Returns the album bio for the given album."""
data = request.get_json() data = request.get_json()
fetch_bio = FetchAlbumBio(data["album"], data["albumartist"]) album_hash = data["hash"]
bio = fetch_bio()
album = instances.album_instance.find_album_by_hash(album_hash)
bio = FetchAlbumBio(album["title"], album["artist"])()
if bio is None: if bio is None:
return {"bio": "No bio found."}, 404 return {"bio": "No bio found."}, 404
@@ -86,8 +87,7 @@ def get_albumartists():
"""Returns a list of artists featured in a given album.""" """Returns a list of artists featured in a given album."""
data = request.get_json() data = request.get_json()
album, artist = data["album"], data["artist"] albumhash = data["hash"]
albumhash = helpers.create_album_hash(album, artist)
tracks = instances.tracks_instance.find_tracks_by_hash(albumhash) tracks = instances.tracks_instance.find_tracks_by_hash(albumhash)
tracks = [models.Track(t) for t in tracks] tracks = [models.Track(t) for t in tracks]
+3 -3
View File
@@ -23,7 +23,7 @@
v-for="option in context.options" v-for="option in context.options"
:key="option.label" :key="option.label"
:class="[{ critical: option.critical }, option.type]" :class="[{ critical: option.critical }, option.type]"
@click="option.action" @click="option.action()"
> >
<div class="icon image" :class="option.icon"></div> <div class="icon image" :class="option.icon"></div>
<div class="label ellip">{{ option.label }}</div> <div class="label ellip">{{ option.label }}</div>
@@ -32,7 +32,7 @@
<div <div
class="context-item" class="context-item"
v-for="child in option.children" v-for="child in option.children"
:key="child" :key="child.label"
:class="[{ critical: child.critical }, child.type]" :class="[{ critical: child.critical }, child.type]"
@click="child.action()" @click="child.action()"
> >
@@ -177,7 +177,7 @@ const context = useContextStore();
.context-normalizedY { .context-normalizedY {
.context-item > .children { .context-item > .children {
transform-origin: bottom right; transform-origin: bottom right;
top: -.5rem; top: -0.5rem;
} }
} }
+1 -2
View File
@@ -42,8 +42,7 @@
:to="{ :to="{
name: 'AlbumView', name: 'AlbumView',
params: { params: {
album: props.song.album, hash: props.song.albumhash,
artist: props.song.albumartist,
}, },
}" }"
> >
+8 -15
View File
@@ -3,11 +3,7 @@ import { AlbumInfo, Track } from "../../interfaces";
import useAxios from "../useAxios"; import useAxios from "../useAxios";
import { NotifType, useNotifStore } from "@/stores/notification"; import { NotifType, useNotifStore } from "@/stores/notification";
const getAlbumData = async ( const getAlbumData = async (hash: string, ToastStore: typeof useNotifStore) => {
album: string,
artist: string,
ToastStore: typeof useNotifStore
) => {
const url = state.settings.uri + "/album"; const url = state.settings.uri + "/album";
interface AlbumData { interface AlbumData {
@@ -18,8 +14,7 @@ const getAlbumData = async (
const { data, status } = await useAxios({ const { data, status } = await useAxios({
url, url,
props: { props: {
album: album, hash: hash,
artist: artist,
}, },
}); });
@@ -27,8 +22,8 @@ const getAlbumData = async (
ToastStore().showNotification("Album not created yet!", NotifType.Error); ToastStore().showNotification("Album not created yet!", NotifType.Error);
return { return {
info: { info: {
album: album, album: "",
artist: artist, artist: "",
}, },
tracks: [], tracks: [],
}; };
@@ -37,12 +32,11 @@ const getAlbumData = async (
return data as AlbumData; return data as AlbumData;
}; };
const getAlbumArtists = async (album: string, artist: string) => { const getAlbumArtists = async (hash: string) => {
const { data, error } = await useAxios({ const { data, error } = await useAxios({
url: state.settings.uri + "/album/artists", url: state.settings.uri + "/album/artists",
props: { props: {
album: album, hash: hash,
artist: artist,
}, },
}); });
@@ -53,12 +47,11 @@ const getAlbumArtists = async (album: string, artist: string) => {
return data.artists; return data.artists;
}; };
const getAlbumBio = async (album: string, albumartist: string) => { const getAlbumBio = async (hash: string) => {
const { data, status } = await useAxios({ const { data, status } = await useAxios({
url: state.settings.uri + "/album/bio", url: state.settings.uri + "/album/bio",
props: { props: {
album: album, hash: hash,
albumartist: albumartist,
}, },
}); });
+7 -4
View File
@@ -1,7 +1,10 @@
import { Playlist, Track } from "../interfaces"; import { Playlist, Track } from "../interfaces";
import Router from "../router"; import Router from "../router";
import { Option } from "../interfaces"; import { Option } from "../interfaces";
import { getAllPlaylists, addTrackToPlaylist } from "../composables/pages/playlists"; import {
getAllPlaylists,
addTrackToPlaylist,
} from "../composables/pages/playlists";
import useQueueStore from "../stores/queue"; import useQueueStore from "../stores/queue";
import useModalStore from "../stores/modal"; import useModalStore from "../stores/modal";
@@ -15,7 +18,7 @@ import useModalStore from "../stores/modal";
export default async ( export default async (
track: Track, track: Track,
modalStore: typeof useModalStore, modalStore: typeof useModalStore,
QueueStore: typeof useQueueStore, QueueStore: typeof useQueueStore
): Promise<Option[]> => { ): Promise<Option[]> => {
const separator: Option = { const separator: Option = {
type: "separator", type: "separator",
@@ -79,7 +82,7 @@ export default async (
QueueStore().playTrackNext(track); QueueStore().playTrackNext(track);
}, },
icon: "add_to_queue", icon: "add_to_queue",
} };
const go_to_folder: Option = { const go_to_folder: Option = {
label: "Go to Folder", label: "Go to Folder",
@@ -114,7 +117,7 @@ export default async (
action: () => { action: () => {
Router.push({ Router.push({
name: "AlbumView", name: "AlbumView",
params: { album: track.album, artist: track.albumartist }, params: { hash: track.albumhash },
}); });
}, },
icon: "album", icon: "album",
+1 -1
View File
@@ -45,7 +45,7 @@ export interface Artist {
export interface Option { export interface Option {
type?: string; type?: string;
label?: string; label?: string;
action?: Function; action?: () => void;
children?: Option[] | false; children?: Option[] | false;
icon?: string; icon?: string;
critical?: Boolean; critical?: Boolean;
+3 -6
View File
@@ -62,17 +62,14 @@ const routes = [
component: AlbumsExplorer, component: AlbumsExplorer,
}, },
{ {
path: "/albums/:album/:artist", path: "/albums/:hash",
name: "AlbumView", name: "AlbumView",
component: AlbumView, component: AlbumView,
beforeEnter: async (to) => { beforeEnter: async (to) => {
state.loading.value = true; state.loading.value = true;
await useAStore().fetchTracksAndArtists( await useAStore().fetchTracksAndArtists(to.params.hash);
to.params.album,
to.params.artist
);
state.loading.value = false; state.loading.value = false;
useAStore().fetchBio(to.params.album, to.params.artist); useAStore().fetchBio(to.params.hash);
}, },
}, },
{ {
+6 -7
View File
@@ -21,9 +21,9 @@ export default defineStore("album", {
* @param title title of the album * @param title title of the album
* @param albumartist artist of the album * @param albumartist artist of the album
*/ */
async fetchTracksAndArtists(title: string, albumartist: string) { async fetchTracksAndArtists(hash: string) {
const tracks = await getAlbumTracks(title, albumartist, useNotifStore); const tracks = await getAlbumTracks(hash, useNotifStore);
const artists = await getAlbumArtists(title, albumartist); const artists = await getAlbumArtists(hash);
this.tracks = tracks.tracks; this.tracks = tracks.tracks;
this.info = tracks.info; this.info = tracks.info;
@@ -31,12 +31,11 @@ export default defineStore("album", {
}, },
/** /**
* Fetches the album bio from the server * Fetches the album bio from the server
* @param title title of the album * @param {string} hash title of the album
* @param albumartist artist of the album
*/ */
fetchBio(title: string, albumartist: string) { fetchBio(hash: string) {
this.bio = null; this.bio = null;
getAlbumBio(title, albumartist).then((bio) => { getAlbumBio(hash).then((bio) => {
this.bio = bio; this.bio = bio;
}); });
}, },
+1 -4
View File
@@ -29,10 +29,7 @@ import { onBeforeRouteUpdate } from "vue-router";
const album = useAStore(); const album = useAStore();
onBeforeRouteUpdate(async (to) => { onBeforeRouteUpdate(async (to) => {
await album.fetchTracksAndArtists( await album.fetchTracksAndArtists(to.params.hash.toString());
to.params.album.toString(),
to.params.artist.toString()
);
album.fetchBio(to.params.album.toString(), to.params.artist.toString()); album.fetchBio(to.params.album.toString(), to.params.artist.toString());
}); });
</script> </script>