Add baseUrl support
This commit is contained in:
		
							parent
							
								
									2e3d517207
								
							
						
					
					
						commit
						132974959b
					
				|  | @ -20,6 +20,7 @@ | ||||||
| 
 | 
 | ||||||
|     // Params |     // Params | ||||||
|     const params = new URL(location.href).searchParams |     const params = new URL(location.href).searchParams | ||||||
|  |     const baseUrl = params.get('b') ?? params.get('instance') ?? '' | ||||||
|     const type = params.get('type') |     const type = params.get('type') | ||||||
|     const id = params.get('id') |     const id = params.get('id') | ||||||
| 
 | 
 | ||||||
|  | @ -38,7 +39,7 @@ | ||||||
|     const cover = reactive({ value: DEFAULT_COVER }) |     const cover = reactive({ value: DEFAULT_COVER }) | ||||||
| 
 | 
 | ||||||
|     const fetchArtistCover = async (id) => { |     const fetchArtistCover = async (id) => { | ||||||
|       const response = await fetch(`/api/v1/artists/${id}/`) |       const response = await fetch(`${baseUrl}/api/v1/artists/${id}/`) | ||||||
|       const data = await response.json() |       const data = await response.json() | ||||||
|       cover.value = data.cover?.urls.medium_square_crop ?? DEFAULT_COVER |       cover.value = data.cover?.urls.medium_square_crop ?? DEFAULT_COVER | ||||||
|     } |     } | ||||||
|  | @ -51,16 +52,23 @@ | ||||||
|     const tracks = reactive([]) |     const tracks = reactive([]) | ||||||
| 
 | 
 | ||||||
|     const getTracksUrl = () => type === 'track' |     const getTracksUrl = () => type === 'track' | ||||||
|       ? `/api/v1/tracks/${id}` |       ? `${baseUrl}/api/v1/tracks/${id}` | ||||||
|       :  type === 'playlist' |       :  type === 'playlist' | ||||||
|         ? `/api/v1/playlists/${id}/tracks/` |         ? ${baseUrl}`/api/v1/playlists/${id}/tracks/` | ||||||
|         : `/api/v1/tracks/` |         : ${baseUrl}`/api/v1/tracks/` | ||||||
| 
 | 
 | ||||||
|     const getAudioSources = (uploads) => { |     const getAudioSources = (uploads) => { | ||||||
|       const sources = uploads |       const sources = uploads | ||||||
|         // NOTE: Filter out repeating and unplayable media types |         // NOTE: Filter out repeating and unplayable media types | ||||||
|         .filter(({ mimetype }, index, array) => array.findIndex((upload) => upload.mimetype === mimetype) === index) |         .filter(({ mimetype }, index, array) => array.findIndex((upload) => upload.mimetype === mimetype) === index) | ||||||
|         .filter(({ mimetype }) => ['probably', 'maybe'].includes(audio.element?.canPlayType(mimetype))) |         .filter(({ mimetype }) => ['probably', 'maybe'].includes(audio.element?.canPlayType(mimetype))) | ||||||
|  |         // NOTE: For backwards compatibilty, prepend the baseUrl if listen_url starts with a slash | ||||||
|  |         .map(source => ({ | ||||||
|  |           ...source, | ||||||
|  |           listen_url: listen_url[0] === '/' | ||||||
|  |             ? `${baseUrl}${listen_url}` | ||||||
|  |             : listen_url | ||||||
|  |         })) | ||||||
| 
 | 
 | ||||||
|       // NOTE: Add a transcoded MP3 src at the end for browsers |       // NOTE: Add a transcoded MP3 src at the end for browsers | ||||||
|       //       that do not support other codecs to be able to play it :) |       //       that do not support other codecs to be able to play it :) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 wvffle
						wvffle