Add support for many missing raw formats (#2834)

* Allow upload of AVIF and x-canon-cr2 mime types

* Allow generic RAW file mime type image/x-dcraw

* Another place to uploading avif and cr2

* Determine mime type for .avif and .cr2 files correctly

* Update asset-upload.config.spec.ts for CR2 and AVIF files

* More changes for AVIF & CR2 files

Found some other places where avif and cr2 should be mentioned.

* Merge in upstream changes

* Allow uploading and using most of the formats that libraw supports

* Add raw files to allowable mobile uploads

* Update asset-upload.config.spec.ts

Fix errant commas.

* Update asset-utils.ts

Remove duplicate entry in hash table.

* Fix missing k25 mime type in server upload check.
Fix prettier formatting message in web file-uploader.

* fix test

---------

Co-authored-by: Elliot Lee <sopwith@gmail.com>
Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
This commit is contained in:
Elliot Lee 2023-06-19 22:10:29 -04:00 committed by GitHub
parent c404ea20ee
commit 81e2b18531
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 129 additions and 4 deletions

View file

@ -47,6 +47,9 @@ class FileHelper {
case 'webm':
return {"type": "video", "subType": "webm"};
case 'avif':
return {"type": "image", "subType": "avif"};
case 'insp':
return {"type": "image", "subType": "jpeg"};
@ -56,6 +59,81 @@ class FileHelper {
case 'arw':
return {"type": "image", "subType": "x-sony-arw"};
case 'raf':
return {"type": "image", "subType": "x-fuji-raf"};
case 'nef':
return {"type": "image", "subType": "x-nikon-nef"};
case 'srw':
return {"type": "image", "subType": "x-samsung-srw"};
case 'crw':
return {"type": "image", "subType": "x-canon-crw"};
case 'cr2':
return {"type": "image", "subType": "x-canon-cr2"};
case 'cr3':
return {"type": "image", "subType": "x-canon-cr3"};
case 'erf':
return {"type": "image", "subType": "x-epson-erf"};
case 'dcr':
return {"type": "image", "subType": "x-kodak-dcr"};
case 'k25':
return {"type": "image", "subType": "x-kodak-k25"};
case 'kdc':
return {"type": "image", "subType": "x-kodak-kdc"};
case 'mrw':
return {"type": "image", "subType": "x-minolta-mrw"};
case 'orf':
return {"type": "image", "subType": "x-olympus-orf"};
case 'raw':
return {"type": "image", "subType": "x-panasonic-raw"};
case 'pef':
return {"type": "image", "subType": "x-panasonic-pef"};
case 'x3f':
return {"type": "image", "subType": "x-sigma-x3f"};
case 'srf':
return {"type": "image", "subType": "x-sony-srf"};
case 'sr2':
return {"type": "image", "subType": "x-sony-sr2"};
case '3fr':
return {"type": "image", "subType": "x-hasselblad-3fr"};
case 'fff':
return {"type": "image", "subType": "x-hasselblad-fff"};
case 'rwl':
return {"type": "image", "subType": "x-leica-rwl"};
case 'ori':
return {"type": "image", "subType": "x-olympus-ori"};
case 'iiq':
return {"type": "image", "subType": "x-phaseone-iiq"};
case 'ari':
return {"type": "image", "subType": "x-arriflex-ari"};
case 'cap':
return {"type": "image", "subType": "x-phaseone-cap"};
case 'cin':
return {"type": "image", "subType": "x-phantom-cin"};
default:
return {"type": "unsupport", "subType": "unsupport"};
}

View file

@ -59,11 +59,34 @@ describe('assetUploadOption', () => {
{ mimetype: 'image/png', extension: 'png' },
{ mimetype: 'image/tiff', extension: 'tiff' },
{ mimetype: 'image/webp', extension: 'webp' },
{ mimetype: 'image/avif', extension: 'avif' },
{ mimetype: 'image/x-adobe-dng', extension: 'dng' },
{ mimetype: 'image/x-fuji-raf', extension: 'raf' },
{ mimetype: 'image/x-nikon-nef', extension: 'nef' },
{ mimetype: 'image/x-samsung-srw', extension: 'srw' },
{ mimetype: 'image/x-sony-arw', extension: 'arw' },
{ mimetype: 'image/x-canon-crw', extension: 'crw' },
{ mimetype: 'image/x-canon-cr2', extension: 'cr2' },
{ mimetype: 'image/x-canon-cr3', extension: 'cr3' },
{ mimetype: 'image/x-epson-erf', extension: 'erf' },
{ mimetype: 'image/x-kodak-dcr', extension: 'dcr' },
{ mimetype: 'image/x-kodak-k25', extension: 'k25' },
{ mimetype: 'image/x-kodak-kdc', extension: 'kdc' },
{ mimetype: 'image/x-minolta-mrw', extension: 'mrw' },
{ mimetype: 'image/x-olympus-orf', extension: 'orf' },
{ mimetype: 'image/x-panasonic-raw', extension: 'raw' },
{ mimetype: 'image/x-pentax-pef', extension: 'pef' },
{ mimetype: 'image/x-sigma-x3f', extension: 'x3f' },
{ mimetype: 'image/x-sony-srf', extension: 'srf' },
{ mimetype: 'image/x-sony-sr2', extension: 'sr2' },
{ mimetype: 'image/x-hasselblad-3fr', extension: '3fr' },
{ mimetype: 'image/x-hasselblad-fff', extension: 'fff' },
{ mimetype: 'image/x-leica-rwl', extension: 'rwl' },
{ mimetype: 'image/x-olympus-ori', extension: 'ori' },
{ mimetype: 'image/x-phaseone-iiq', extension: 'iiq' },
{ mimetype: 'image/x-arriflex-ari', extension: 'ari' },
{ mimetype: 'image/x-phaseone-cap', extension: 'cap' },
{ mimetype: 'image/x-phantom-cin', extension: 'cin' },
{ mimetype: 'video/avi', extension: 'avi' },
{ mimetype: 'video/mov', extension: 'mov' },
{ mimetype: 'video/mp4', extension: 'mp4' },

View file

@ -55,7 +55,7 @@ function fileFilter(req: AuthRequest, file: any, cb: any) {
}
if (
file.mimetype.match(
/\/(jpg|jpeg|png|gif|avi|mov|mp4|webm|x-msvideo|quicktime|heic|heif|dng|x-adobe-dng|webp|tiff|3gpp|nef|x-nikon-nef|x-fuji-raf|x-samsung-srw|mpeg|x-flv|x-ms-wmv|x-matroska|x-sony-arw|arw)$/,
/\/(jpg|jpeg|png|gif|avi|mov|mp4|webm|x-msvideo|quicktime|heic|heif|avif|dng|x-adobe-dng|webp|tiff|3gpp|nef|x-nikon-nef|x-fuji-raf|x-samsung-srw|mpeg|x-flv|x-ms-wmv|x-matroska|x-sony-arw|arw|x-canon-crw|x-canon-cr2|x-canon-cr3|x-epson-erf|x-kodak-dcr|x-kodak-kdc|x-kodak-k25|x-minolta-mrw|x-olympus-orf|x-panasonic-raw|x-pentax-pef|x-sigma-x3f|x-sony-srf|x-sony-sr2|x-hasselblad-3fr|x-hasselblad-fff|x-leica-rwl|x-olympus-ori|x-phaseone-iiq|x-arriflex-ari|x-phaseone-cap|x-phantom-cin)$/,
)
) {
cb(null, true);

View file

@ -25,7 +25,7 @@ function fileFilter(req: AuthRequest, file: any, cb: any) {
return cb(new UnauthorizedException());
}
if (file.mimetype.match(/\/(jpg|jpeg|png|heic|heif|dng|webp)$/)) {
if (file.mimetype.match(/\/(jpg|jpeg|png|heic|heif|dng|webp|avif)$/)) {
cb(null, true);
} else {
cb(new BadRequestException(`Unsupported file type ${extname(file.originalname)}`), false);

View file

@ -131,11 +131,34 @@ export function getFileMimeType(file: File): string {
dng: 'image/dng',
heic: 'image/heic',
heif: 'image/heif',
avif: 'image/avif',
insp: 'image/jpeg',
insv: 'video/mp4',
nef: 'image/x-nikon-nef',
raf: 'image/x-fuji-raf',
srw: 'image/x-samsung-srw'
srw: 'image/x-samsung-srw',
crw: 'image/x-canon-crw',
cr2: 'image/x-canon-cr2',
cr3: 'image/x-canon-cr3',
erf: 'image/x-epson-erf',
dcr: 'image/x-kodak-dcr',
k25: 'image/x-kodak-k25',
kdc: 'image/x-kodak-kdc',
mrw: 'image/x-minolta-mrw',
orf: 'image/x-olympus-orf',
raw: 'image/x-panasonic-raw',
pef: 'image/x-pentax-pef',
x3f: 'image/x-sigma-x3f',
srf: 'image/x-sony-srf',
sr2: 'image/x-sony-sr2',
'3fr': 'image/x-hasselblad-3fr',
fff: 'image/x-hasselblad-fff',
rwl: 'image/x-leica-rwl',
ori: 'image/x-olympus-ori',
iiq: 'image/x-phaseone-iiq',
ari: 'image/x-arriflex-ari',
cap: 'image/x-phaseone-cap',
cin: 'image/x-phantom-cin'
};
// Return the MIME type determined by the browser or the MIME type based on the file extension.
return file.type || (mimeTypes[getFilenameExtension(file.name)] ?? '');

View file

@ -22,7 +22,8 @@ export const openFileUploadDialog = async (
// When adding a content type that is unsupported by browsers, make sure
// to also add it to getFileMimeType() otherwise the upload will fail.
fileSelector.accept = 'image/*,video/*,.heic,.heif,.dng,.3gp,.nef,.srw,.raf,.insp,.insv,.arw';
fileSelector.accept =
'image/*,video/*,.heic,.heif,.avif,.dng,.3gp,.nef,.srw,.crw,.cr2,.cr3,.raf,.insp,.insv,.arw,.erf,.raf,.dcr,.k25,.kdc,.mrw,.orf,.raw,.pef,.x3f,.srf,.sr2,.3fr,.fff,.rwl,.ori,.iiq,.ari,.cap,.cin';
fileSelector.onchange = async (e: Event) => {
const target = e.target as HTMLInputElement;