@@ -19,6 +19,8 @@ import { getCoverArtCache, setCoverArtCache } from "./coverArtCache";
19
19
const originalFetch = window . fetch ;
20
20
const fetchWithRetry = require ( "fetch-retry" ) ( originalFetch ) ;
21
21
22
+ let APIServiceInstance = new APIServiceClass ( `${ window . location . origin } /1` ) ;
23
+
22
24
const searchForSpotifyTrack = async (
23
25
spotifyToken ?: string ,
24
26
trackName ?: string ,
@@ -611,6 +613,7 @@ const getPageProps = async (): Promise<{
611
613
const apiService = new APIServiceClass (
612
614
api_url || `${ window . location . origin } /1`
613
615
) ;
616
+ APIServiceInstance = apiService ;
614
617
globalAppContext = {
615
618
APIService : apiService ,
616
619
websocketsUrl : websockets_url ,
@@ -800,14 +803,13 @@ const getAlbumArtFromReleaseGroupMBID = async (
800
803
801
804
const getAlbumArtFromReleaseMBID = async (
802
805
userSubmittedReleaseMBID : string | undefined | null ,
803
- useReleaseGroupFallback : boolean | string = false ,
804
- APIService ?: APIServiceClass ,
806
+ userSubmittedReleaseGroupMBID : string | undefined | null ,
805
807
optionalSize ?: CAAThumbnailSizes ,
806
808
frontOnly ?: boolean
807
809
) : Promise < string | undefined > => {
808
810
try {
809
811
// Check cache first
810
- const cacheKey = `ca:${ userSubmittedReleaseMBID } -${ optionalSize } -${ useReleaseGroupFallback } ` ;
812
+ const cacheKey = `ca:${ userSubmittedReleaseMBID } -${ optionalSize } -${ userSubmittedReleaseGroupMBID } ` ;
811
813
const cachedCoverArt = await getCoverArtCache ( cacheKey ) ;
812
814
if ( cachedCoverArt ) {
813
815
return cachedCoverArt ;
@@ -833,15 +835,20 @@ const getAlbumArtFromReleaseMBID = async (
833
835
}
834
836
}
835
837
836
- if ( useReleaseGroupFallback ) {
837
- let releaseGroupMBID = useReleaseGroupFallback ;
838
+ /*
839
+ Fallback to fetching cover art for the Release Group.
840
+ If no RG MBID is available, first hit the MusicBrainz API
841
+ with the release MBID to get the RG MBID
842
+ */
843
+ if ( userSubmittedReleaseMBID || userSubmittedReleaseGroupMBID ) {
844
+ let releaseGroupMBID = userSubmittedReleaseGroupMBID ;
838
845
if (
839
- _ . isString ( userSubmittedReleaseMBID ) &&
840
- ! _ . isString ( useReleaseGroupFallback ) &&
841
- APIService
846
+ ! _ . isString ( userSubmittedReleaseGroupMBID ) &&
847
+ _ . isString ( userSubmittedReleaseMBID )
842
848
) {
843
- const releaseGroupResponse = ( await APIService . lookupMBRelease (
844
- userSubmittedReleaseMBID
849
+ const releaseGroupResponse = ( await APIServiceInstance . lookupMBRelease (
850
+ userSubmittedReleaseMBID ,
851
+ "release-groups"
845
852
) ) as MusicBrainzRelease & WithReleaseGroup ;
846
853
releaseGroupMBID = releaseGroupResponse [ "release-group" ] . id ;
847
854
}
@@ -919,8 +926,7 @@ const getAlbumArtFromListenMetadataKey = (
919
926
920
927
const getAlbumArtFromListenMetadata = async (
921
928
listen : BaseListenFormat ,
922
- spotifyUser ?: SpotifyUser ,
923
- APIService ?: APIServiceClass
929
+ spotifyUser ?: SpotifyUser
924
930
) : Promise < string | undefined > => {
925
931
if ( ! listen ) {
926
932
return undefined ;
@@ -954,8 +960,7 @@ const getAlbumArtFromListenMetadata = async (
954
960
// release group cover art of the user submitted release mbid next
955
961
const userSubmittedReleaseAlbumArt = await getAlbumArtFromReleaseMBID (
956
962
userSubmittedReleaseMBID ,
957
- userSubmittedReleaseGroupMBID ?? true ,
958
- APIService ,
963
+ userSubmittedReleaseGroupMBID ,
959
964
undefined ,
960
965
true // we only want front images, otherwise skip
961
966
) ;
0 commit comments