fix: accept any valid mime type for downloadable tracks
This commit is contained in:
@@ -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({
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
/**
|
||||
* The filetypes this application will most probably receive.
|
||||
* Adapted from: https://github.com/jellyfin/jellyfin/blob/63d943aab92a4b5f69e625a269eb830bcbfb4d22/MediaBrowser.Model/Net/MimeTypes.cs#L107
|
||||
*/
|
||||
const MimeTypes = {
|
||||
'audio/aac': '.aac',
|
||||
'audio/ac3': '.ac3',
|
||||
'audio/dsf': '.dsf',
|
||||
'audio/dsp': '.dsp',
|
||||
'audio/flac': '.flac',
|
||||
'audio/m4b': '.m4b',
|
||||
'audio/mp4': '.m4a',
|
||||
'audio/mpeg': '.mp3',
|
||||
'audio/vorbis': '.vorbis',
|
||||
'audio/x-ape': '.ape',
|
||||
'audio/xsp': '.xsp',
|
||||
'audio/x-wavpack': '.wv',
|
||||
'audio/ogg': '.ogg',
|
||||
};
|
||||
|
||||
export default MimeTypes;
|
||||
Reference in New Issue
Block a user