WIP
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
"build": "tsc -b && tsc -p tsconfig.client.json",
|
||||
"test": "vitest run",
|
||||
"test:watch": "vitest",
|
||||
"test:container": "podman build --build-arg PACKAGE_VERSION=$(npm pkg get version | xargs) --format docker -f ../Dockerfile.upload -t immich-proxy-upload-test .. && podman run --init -it -p=3001:3000 --env-file .env -e IPP_PORT=3000 --restart=always immich-proxy-upload-test",
|
||||
"start": "node dist/index.js"
|
||||
},
|
||||
"author": "Alan Grainger",
|
||||
|
||||
@@ -19,7 +19,7 @@ export function isUploadableType (mimeType: string): boolean {
|
||||
}
|
||||
|
||||
/*
|
||||
Types for files a desktop browser reports with an empty `File.type`: HEIC,
|
||||
Types for files a desktop browser reports with an empty or generic `File.type`: HEIC,
|
||||
HEIF, camera RAW and some video containers. Immich types the asset by its
|
||||
extension, so these only need to pass `isUploadableType`.
|
||||
*/
|
||||
@@ -46,11 +46,15 @@ const TYPE_BY_EXTENSION: Record<string, string> = {
|
||||
insv: 'video/mp4'
|
||||
}
|
||||
|
||||
/** The browser's type for a file, or one derived from its extension when the browser gives none. */
|
||||
/**
|
||||
* The browser's type for a file, or one derived from its extension when the
|
||||
* browser gives none or a generic one (Chrome reports HEIC from the file
|
||||
* picker as `application/octet-stream`).
|
||||
*/
|
||||
export function fileType (name: string, browserType: string): string {
|
||||
if (browserType) return browserType
|
||||
if (isUploadableType(browserType)) return browserType
|
||||
const extension = name.split('.').pop()?.toLowerCase() || ''
|
||||
return TYPE_BY_EXTENSION[extension] || ''
|
||||
return TYPE_BY_EXTENSION[extension] || browserType
|
||||
}
|
||||
|
||||
/** Bytes as a short human-readable string. */
|
||||
|
||||
@@ -27,6 +27,14 @@ describe('fileType', () => {
|
||||
expect(fileType('IMG_0042.HEIC', 'image/heic')).toBe('image/heic')
|
||||
})
|
||||
|
||||
it('derives a type from the extension when the browser gives a generic one', () => {
|
||||
expect(fileType('IMG_0042.HEIC', 'application/octet-stream')).toBe('image/heic')
|
||||
})
|
||||
|
||||
it('keeps a generic type it cannot improve on, so the client refuses the file', () => {
|
||||
expect(fileType('notes.txt', 'application/octet-stream')).toBe('application/octet-stream')
|
||||
})
|
||||
|
||||
it('derives a type from the extension when the browser gives none', () => {
|
||||
expect(fileType('IMG_0042.HEIC', '')).toBe('image/heic')
|
||||
expect(fileType('DSC_0001.NEF', '')).toBe('image/x-nikon-nef')
|
||||
|
||||
Reference in New Issue
Block a user