feat: attempt to retrieve images from downloaded items

This commit is contained in:
Lei Nelissen
2025-05-24 00:22:31 +02:00
parent 09a020afbb
commit cf8bfdf05a
3 changed files with 28 additions and 19 deletions

View File

@@ -17,16 +17,17 @@ export const failDownload = createAction<{ id: string }>('download/fail');
export const downloadTrack = createAsyncThunk(
'/downloads/track',
async (id: string, { dispatch }) => {
async (id: string, { dispatch, getState }) => {
// Generate the URL we can use to download the file
const entity = (getState() as AppState).music.tracks.entities[id];
const audioUrl = generateTrackUrl(id);
const imageUrl = getImage(id);
const imageUrl = getImage(entity);
// Get the content-type from the URL by doing a HEAD-only request
const [audioExt, imageExt] = await Promise.all([
getExtensionForUrl(audioUrl),
// Image files may be absent
getExtensionForUrl(imageUrl).catch(() => null)
imageUrl ? getExtensionForUrl(imageUrl).catch(() => null) : null
]);
// Then generate the proper location
@@ -51,7 +52,7 @@ export const downloadTrack = createAsyncThunk(
const { promise: imagePromise } = imageExt && imageLocation
? downloadFile({
fromUrl: imageUrl,
fromUrl: imageUrl!,
toFile: imageLocation,
background: true,
})