diff --git a/server/app/api/album.py b/server/app/api/album.py index 64ed1da3..f4ec080e 100644 --- a/server/app/api/album.py +++ b/server/app/api/album.py @@ -41,20 +41,28 @@ def get_album(): """Returns all the tracks in the given album.""" data = request.get_json() albumhash = data["hash"] + error_msg = {"error": "Album not created yet."} tracks = instances.tracks_instance.find_tracks_by_hash(albumhash) + + if len(tracks) == 0: + return error_msg, 204 + tracks = [models.Track(t) for t in tracks] tracks = helpers.RemoveDuplicates(tracks)() album = instances.album_instance.find_album_by_hash(albumhash) if not album: - return {"error": "Album not created yet."}, 204 + return error_msg, 204 album = models.Album(album) album.count = len(tracks) - album.duration = albumslib.get_album_duration(tracks) + try: + album.duration = albumslib.get_album_duration(tracks) + except AttributeError: + album.duration = 0 if ( album.count == 1 diff --git a/server/app/db/mongodb/albums.py b/server/app/db/mongodb/albums.py index 4999c146..eeceb6d0 100644 --- a/server/app/db/mongodb/albums.py +++ b/server/app/db/mongodb/albums.py @@ -61,11 +61,11 @@ class Albums(MongoAlbums): album = self.collection.find_one({"hash": hash}) return convert_one(album) - def set_album_colors(self, colors: List[str], album_id: str) -> None: + def set_album_colors(self, colors: List[str], hash: str) -> None: """ Sets the colors for an album. """ self.collection.update_one( - {"_id": ObjectId(album_id)}, + {"hash": hash}, {"$set": {"colors": colors}}, ) diff --git a/server/app/lib/colorlib.py b/server/app/lib/colorlib.py index e410d870..38f8e481 100644 --- a/server/app/lib/colorlib.py +++ b/server/app/lib/colorlib.py @@ -45,6 +45,6 @@ class ProcessAlbumColors: colors = get_image_colors(img) if len(colors) > 0: - instances.album_instance.set_album_colors(colors, album.albumid) + instances.album_instance.set_album_colors(colors, album.hash) return colors diff --git a/server/app/models.py b/server/app/models.py index 3cb4d42b..fc24ed12 100644 --- a/server/app/models.py +++ b/server/app/models.py @@ -82,7 +82,6 @@ class Album: Creates an album object """ - albumid: str title: str artist: str hash: str @@ -96,7 +95,6 @@ class Album: colors: List[str] = field(default_factory=list) def __init__(self, tags): - self.albumid = tags["_id"]["$oid"] self.title = tags["title"] self.artist = tags["artist"] self.date = tags["date"] diff --git a/src/assets/css/_variables.scss b/src/assets/css/_variables.scss index 52fe2039..caad1304 100644 --- a/src/assets/css/_variables.scss +++ b/src/assets/css/_variables.scss @@ -39,7 +39,7 @@ $teal: rgb(64, 200, 224); $primary: $gray4; -$accent: $darkblue; +$accent: $red; $secondary: $gray5; $cta: $blue; $danger: $red; diff --git a/src/components/AlbumView/Header.vue b/src/components/AlbumView/Header.vue index 7a016d2d..c5b7ea58 100644 --- a/src/components/AlbumView/Header.vue +++ b/src/components/AlbumView/Header.vue @@ -4,7 +4,7 @@ class="a-header rounded" :style="{ backgroundImage: `linear-gradient( - 37deg, ${album.colors[0]}, ${album.colors[3]} + 37deg, ${props.album.colors[0]}, ${props.album.colors[3]} )`, }" > @@ -17,7 +17,7 @@ v-motion-slide-from-left > -