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

25
package-lock.json generated
View File

@@ -25,6 +25,7 @@
"fuse.js": "^7.0.0",
"i18n-js": "^4.3.2",
"lodash": "^4.17.21",
"mime-db": "^1.53.0",
"react": "^18.2.0",
"react-airplay": "^1.2.0",
"react-native": "0.74.3",
@@ -58,6 +59,7 @@
"@sentry/react-native": "^5.26.0",
"@types/i18n-js": "^3.8.9",
"@types/lodash": "^4.14.202",
"@types/mime-db": "^1.43.5",
"@types/node": "^20.11.17",
"@types/react": "^18.2.55",
"@typescript-eslint/eslint-plugin": "^6.21.0",
@@ -3782,6 +3784,13 @@
"integrity": "sha512-OvlIYQK9tNneDlS0VN54LLd5uiPCBOp7gS5Z0f1mjoJYBrtStzgmJBxONW3U6OZqdtNzZPmn9BS/7WI7BFFcFQ==",
"dev": true
},
"node_modules/@types/mime-db": {
"version": "1.43.5",
"resolved": "https://registry.npmjs.org/@types/mime-db/-/mime-db-1.43.5.tgz",
"integrity": "sha512-/bfTiIUTNPUBnwnYvUxXAre5MhD88jgagLEQiQtIASjU+bwxd8kS/ASDA4a8ufd8m0Lheu6eeMJHEUpLHoJ28A==",
"dev": true,
"license": "MIT"
},
"node_modules/@types/node": {
"version": "20.11.17",
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.17.tgz",
@@ -8415,9 +8424,10 @@
}
},
"node_modules/mime-db": {
"version": "1.52.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
"version": "1.53.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.53.0.tgz",
"integrity": "sha512-oHlN/w+3MQ3rba9rqFr6V/ypF10LSkdwUysQL7GkXoTgIWeV+tcXGA852TBxH+gsh8UWoyhR1hKcoMJTuWflpg==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
@@ -8433,6 +8443,15 @@
"node": ">= 0.6"
}
},
"node_modules/mime-types/node_modules/mime-db": {
"version": "1.52.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/mimic-fn": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz",

View File

@@ -28,6 +28,7 @@
"fuse.js": "^7.0.0",
"i18n-js": "^4.3.2",
"lodash": "^4.17.21",
"mime-db": "^1.53.0",
"react": "^18.2.0",
"react-airplay": "^1.2.0",
"react-native": "0.74.3",
@@ -61,6 +62,7 @@
"@sentry/react-native": "^5.26.0",
"@types/i18n-js": "^3.8.9",
"@types/lodash": "^4.14.202",
"@types/mime-db": "^1.43.5",
"@types/node": "^20.11.17",
"@types/react": "^18.2.55",
"@typescript-eslint/eslint-plugin": "^6.21.0",

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({

View File

@@ -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;