commit 0a06102a2d7d2f073e02b9be0945f7725f1076cb
parent e2bed95fda636e26d591fd24cf4efa267e392a80
Author: mtmn <miro@haravara.org>
Date: Thu, 23 Apr 2026 00:42:30 +0200
feat: simplify cover sources logic
Diffstat:
2 files changed, 22 insertions(+), 12 deletions(-)
diff --git a/src/Cover.purs b/src/Cover.purs
@@ -71,7 +71,7 @@ fetchLastfmCoverUrl cfg artist release = case cfg.lastfmApiKey of
<> k
Log.info $ "Searching Last.fm for: " <> artist <> " - " <> release
let headers = { "User-Agent": "corpus/1.0 (+https://github.com/mtmn/corpus)" }
- result <- try $ fetch searchUrl { method: GET, headers }
+ result <- try $ fetch searchUrl { method: GET, headers }
case result of
Right fr | fr.status == 200 -> do
json <- fromJson fr.json
@@ -108,17 +108,16 @@ fetchDiscogsCoverUrl cfg artist release = case cfg.discogsToken of
_ ->
pure Nothing
-coverSources :: String -> String -> String -> Maybe String -> UserConfig -> Array CoverSource
-coverSources mbid artist release mVariant cfg =
+coverSources :: String -> String -> String -> String -> UserConfig -> Array CoverSource
+coverSources mbid artist release variant cfg =
let
safeArtist = sanitizeKey artist
safeRelease = sanitizeKey release
- variant = fromMaybe "front-500" mVariant
caaSource =
- if mbid == "" then []
+ if mbid == "" || variant == "" then []
else
[ { name: "caa"
- , s3Key: "covers/caa/" <> sanitizeKey mbid <> (if variant == "front-500" then "" else "-" <> variant) <> ".avif"
+ , s3Key: "covers/caa/" <> sanitizeKey mbid <> "-" <> variant <> ".avif"
, findUrl: pure $ Just $ "https://coverartarchive.org/release/" <> mbid <> "/" <> variant
}
]
@@ -144,7 +143,7 @@ serveCover serveNotFound cfg slug url res = do
mbid = fromMaybe "" (getQueryParam "mbid" url)
artist = fromMaybe "" (getQueryParam "artist" url)
release = fromMaybe "" (getQueryParam "release" url)
- variant = getQueryParam "variant" url
+ variant = fromMaybe "" (getQueryParam "variant" url)
s3cfg = s3ConfigFromUser cfg
served <- foldM (trySource s3cfg) false (coverSources mbid artist release variant cfg)
diff --git a/src/View.elm b/src/View.elm
@@ -209,12 +209,23 @@ renderListen userSlug currentTime failedCovers coverFallbacks hoveredCover simil
variant =
case Dict.get baseCoverUrl coverFallbacks |> Maybe.withDefault 0 of
- 1 -> "&variant=front-250"
- 2 -> "&variant=back-500"
- 3 -> "&variant=back-250"
- _ -> ""
+ 0 ->
+ "front-500"
- coverUrl = baseCoverUrl ++ variant
+ 1 ->
+ "front-250"
+
+ 2 ->
+ "back-500"
+
+ 3 ->
+ "back-250"
+
+ _ ->
+ ""
+
+ coverUrl =
+ baseCoverUrl ++ "&variant=" ++ variant
isZoomed =
hoveredCover == Just idx