feat(web): allow uploading more file types (#1570)

* feat(web): allow uploading more file types

* fix(web): make filename extension lowercase
This commit is contained in:
Michel Heusschen 2023-02-09 17:08:19 +01:00 committed by GitHub
parent 8c20d8cb3d
commit adb265794c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 123 additions and 89 deletions

View file

@ -111,3 +111,38 @@ export async function bulkDownload(
});
}
}
/**
* Returns the lowercase filename extension without a dot (.) and
* an empty string when not found.
*/
export function getFilenameExtension(filename: string): string {
const lastIndex = filename.lastIndexOf('.');
return filename.slice(lastIndex + 1).toLowerCase();
}
/**
* Returns the MIME type of the file and an empty string when not found.
*/
export function getFileMimeType(file: File): string {
if (file.type !== '') {
// Return the MIME type determined by the browser.
return file.type;
}
// Return MIME type based on the file extension.
switch (getFilenameExtension(file.name)) {
case 'heic':
return 'image/heic';
case 'heif':
return 'image/heif';
case 'dng':
return 'image/dng';
case '3gp':
return 'video/3gpp';
case 'nef':
return 'image/nef';
default:
return '';
}
}