From 92e2420174249ba72a3680f33878d00dcedfdc72 Mon Sep 17 00:00:00 2001 From: geoffrey45 Date: Thu, 16 Jun 2022 14:18:45 +0300 Subject: [PATCH] rewrite some fetch methods to use the useAxios hook --- server/app/api/album.py | 5 + server/app/api/playlist.py | 6 +- server/app/models.py | 15 --- src/components/modals/NewPlaylist.vue | 10 +- src/components/modals/updatePlaylist.vue | 16 ++- src/composables/album.ts | 65 ---------- src/composables/fetch/album.ts | 66 +++++++++++ src/composables/fetch/playlists.ts | 130 ++++++++++++++++++++ src/composables/getFilesAndFolders.ts | 35 ++++-- src/composables/playlists.ts | 145 ----------------------- src/composables/useAxios.ts | 32 +++++ src/composables/useKeyboard.ts | 10 +- src/contexts/track_context.ts | 2 +- src/interfaces.ts | 45 +++---- src/stores/pages/album.ts | 3 +- src/stores/pages/playlist.ts | 2 +- src/stores/pages/playlists.ts | 2 +- 17 files changed, 305 insertions(+), 284 deletions(-) delete mode 100644 src/composables/album.ts create mode 100644 src/composables/fetch/album.ts create mode 100644 src/composables/fetch/playlists.ts delete mode 100644 src/composables/playlists.ts create mode 100644 src/composables/useAxios.ts diff --git a/server/app/api/album.py b/server/app/api/album.py index 1ae004a..0b34a24 100644 --- a/server/app/api/album.py +++ b/server/app/api/album.py @@ -40,6 +40,7 @@ def get_albums(): def get_album(): """Returns all the tracks in the given album.""" data = request.get_json() + print(data) album, artist = data["album"], data["artist"] albumhash = helpers.create_album_hash(album, artist) @@ -47,6 +48,10 @@ def get_album(): tracks = [models.Track(t) for t in tracks] album = instances.album_instance.find_album_by_hash(albumhash) + + if not album: + return {"error": "Album not found."}, 404 + album = models.Album(album) album.count = len(tracks) diff --git a/server/app/api/playlist.py b/server/app/api/playlist.py index 5d023c4..b956e80 100644 --- a/server/app/api/playlist.py +++ b/server/app/api/playlist.py @@ -12,7 +12,7 @@ from app.lib import playlistlib from flask import Blueprint from flask import request -from app.helpers import UseBisection, create_new_date +from app.helpers import Get, UseBisection, create_new_date playlist_bp = Blueprint("playlist", __name__, url_prefix="/") @@ -104,7 +104,9 @@ def update_playlist(playlistid: str): "thumb": None, } - p = UseBisection(api.PLAYLISTS, "playlistid", [playlistid])() + playlists = Get.get_all_playlists() + + p = UseBisection(playlists, "playlistid", [playlistid])() p: models.Playlist = p[0] if playlist is not None: diff --git a/server/app/models.py b/server/app/models.py index b8bbfe8..c65c649 100644 --- a/server/app/models.py +++ b/server/app/models.py @@ -143,27 +143,12 @@ class Playlist: self.lastUpdated = data["lastUpdated"] self.count = len(self.pretracks) - def create_img_link(self, image: str): if image: return image return "default.webp" - def update_count(self): - self.count = len(self.pretracks) - - def add_track(self, track): - if track not in self.pretracks: - self.pretracks.append(track) - self.update_count() - self.lastUpdated = helpers.create_new_date() - else: - raise TrackExistsInPlaylist("Track already exists in playlist") - - def update_desc(self, desc): - self.description = desc - def update_playlist(self, data: dict): self.name = data["name"] self.description = data["description"] diff --git a/src/components/modals/NewPlaylist.vue b/src/components/modals/NewPlaylist.vue index 6f4d2d7..ba677e6 100644 --- a/src/components/modals/NewPlaylist.vue +++ b/src/components/modals/NewPlaylist.vue @@ -18,7 +18,7 @@