fix: accept any valid mime type for downloadable tracks

This commit is contained in:
Lei Nelissen
2024-10-12 22:57:20 +02:00
parent 502f39db0e
commit 2c42a897d9
4 changed files with 28 additions and 28 deletions

View File

@@ -2,8 +2,8 @@ import { createAction, createAsyncThunk, createEntityAdapter } from '@reduxjs/to
import { AppState } from '@/store';
import { downloadFile, unlink, DocumentDirectoryPath, exists } from 'react-native-fs';
import { DownloadEntity } from './types';
import MimeTypes from '@/utility/MimeTypes';
import { generateTrackUrl } from '@/utility/JellyfinApi/track';
import db from 'mime-db';
export const downloadAdapter = createEntityAdapter<DownloadEntity>();
@@ -26,13 +26,13 @@ export const downloadTrack = createAsyncThunk(
}
// Then convert the MIME-type to an extension
const extension = MimeTypes[contentType as keyof typeof MimeTypes];
if (!extension) {
const extensions = db[contentType]?.extensions;
if (!extensions?.length) {
throw new Error(`Unsupported MIME-type ${contentType}`);
}
// Then generate the proper location
const location = `${DocumentDirectoryPath}/${id}${extension}`;
const location = `${DocumentDirectoryPath}/${id}.${extensions[0]}`;
// Actually kick off the download
const { promise } = await downloadFile({