mirror of
https://github.com/KevinMidboe/immich.git
synced 2025-10-29 17:40:28 +00:00
fix(server): add missing extensions and mime types (#3318)
Add extensions and mime types which were accidentally removed in #3197. Fixes: #3300
This commit is contained in:
@@ -12,7 +12,6 @@ import {
|
||||
import { when } from 'jest-when';
|
||||
import { Readable } from 'stream';
|
||||
import { ICryptoRepository } from '../crypto';
|
||||
import { mimeTypes } from '../domain.constant';
|
||||
import { IStorageRepository } from '../storage';
|
||||
import { AssetStats, IAssetRepository } from './asset.repository';
|
||||
import { AssetService, UploadFieldName } from './asset.service';
|
||||
@@ -66,30 +65,78 @@ const uploadFile = {
|
||||
},
|
||||
};
|
||||
|
||||
const validImages = [
|
||||
'.3fr',
|
||||
'.ari',
|
||||
'.arw',
|
||||
'.avif',
|
||||
'.cap',
|
||||
'.cin',
|
||||
'.cr2',
|
||||
'.cr3',
|
||||
'.crw',
|
||||
'.dcr',
|
||||
'.dng',
|
||||
'.erf',
|
||||
'.fff',
|
||||
'.gif',
|
||||
'.heic',
|
||||
'.heif',
|
||||
'.iiq',
|
||||
'.jpeg',
|
||||
'.jpg',
|
||||
'.jxl',
|
||||
'.k25',
|
||||
'.kdc',
|
||||
'.mrw',
|
||||
'.nef',
|
||||
'.orf',
|
||||
'.ori',
|
||||
'.pef',
|
||||
'.png',
|
||||
'.raf',
|
||||
'.raw',
|
||||
'.rwl',
|
||||
'.sr2',
|
||||
'.srf',
|
||||
'.srw',
|
||||
'.tiff',
|
||||
'.webp',
|
||||
'.x3f',
|
||||
];
|
||||
|
||||
const validVideos = ['.3gp', '.avi', '.flv', '.m2ts', '.mkv', '.mov', '.mp4', '.mpg', '.mts', '.webm', '.wmv'];
|
||||
|
||||
const uploadTests = [
|
||||
{
|
||||
label: 'asset',
|
||||
label: 'asset images',
|
||||
fieldName: UploadFieldName.ASSET_DATA,
|
||||
filetypes: Object.keys({ ...mimeTypes.image, ...mimeTypes.video }),
|
||||
invalid: ['.xml', '.html'],
|
||||
valid: validImages,
|
||||
invalid: ['.html', '.xml'],
|
||||
},
|
||||
{
|
||||
label: 'asset videos',
|
||||
fieldName: UploadFieldName.ASSET_DATA,
|
||||
valid: validVideos,
|
||||
invalid: ['.html', '.xml'],
|
||||
},
|
||||
{
|
||||
label: 'live photo',
|
||||
fieldName: UploadFieldName.LIVE_PHOTO_DATA,
|
||||
filetypes: Object.keys(mimeTypes.video),
|
||||
invalid: ['.xml', '.html', '.jpg', '.jpeg'],
|
||||
valid: validVideos,
|
||||
invalid: ['.html', '.jpeg', '.jpg', '.xml'],
|
||||
},
|
||||
{
|
||||
label: 'sidecar',
|
||||
fieldName: UploadFieldName.SIDECAR_DATA,
|
||||
filetypes: Object.keys(mimeTypes.sidecar),
|
||||
invalid: ['.xml', '.html', '.jpg', '.jpeg', '.mov', '.mp4'],
|
||||
valid: ['.xmp'],
|
||||
invalid: ['.html', '.jpeg', '.jpg', '.mov', '.mp4', '.xml'],
|
||||
},
|
||||
{
|
||||
label: 'profile',
|
||||
fieldName: UploadFieldName.PROFILE_DATA,
|
||||
filetypes: Object.keys(mimeTypes.profile),
|
||||
invalid: ['.xml', '.html', '.cr2', '.arf', '.mov', '.mp4'],
|
||||
valid: ['.avif', '.dng', '.heic', '.heif', '.jpeg', '.jpg', '.png', '.webp'],
|
||||
invalid: ['.arf', '.cr2', '.html', '.mov', '.mp4', '.xml'],
|
||||
},
|
||||
];
|
||||
|
||||
@@ -117,9 +164,9 @@ describe(AssetService.name, () => {
|
||||
expect(() => sut.canUploadFile(uploadFile.nullAuth)).toThrowError(UnauthorizedException);
|
||||
});
|
||||
|
||||
for (const { fieldName, filetypes, invalid } of uploadTests) {
|
||||
describe(`${fieldName}`, () => {
|
||||
for (const filetype of filetypes) {
|
||||
for (const { fieldName, valid, invalid } of uploadTests) {
|
||||
describe(fieldName, () => {
|
||||
for (const filetype of valid) {
|
||||
it(`should accept ${filetype}`, () => {
|
||||
expect(sut.canUploadFile(uploadFile.filename(fieldName, `asset${filetype}`))).toEqual(true);
|
||||
});
|
||||
@@ -132,6 +179,16 @@ describe(AssetService.name, () => {
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
it('should be sorted (valid)', () => {
|
||||
// TODO: use toSorted in NodeJS 20.
|
||||
expect(valid).toEqual([...valid].sort());
|
||||
});
|
||||
|
||||
it('should be sorted (invalid)', () => {
|
||||
// TODO: use toSorted in NodeJS 20.
|
||||
expect(invalid).toEqual([...invalid].sort());
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user