Update docs

This commit is contained in:
Alan Grainger
2026-10-07 18:04:57 +13:00
parent 7a9ff2e6ee
commit 172f247418
14 changed files with 243 additions and 37 deletions
+11
View File
@@ -15,6 +15,17 @@ describe('uploadFilename', () => {
expect(uploadFilename('we"rd:na*me.jpg', '')).toBe('werdname.jpg')
})
it('removes zero-width and direction-changing characters', () => {
expect(uploadFilename('holiday\u202Egpj.mp4', '')).toBe('holidaygpj.mp4')
expect(uploadFilename('IMG\u200B_0042\uFEFF.jpg', '')).toBe('IMG_0042.jpg')
// Only format characters go: a bidi override cannot hide a dotfile
expect(uploadFilename('\u202E.htaccess', '')).toBeUndefined()
})
it('normalises to NFC so one name has one spelling', () => {
expect(uploadFilename('Cafe\u0301.jpg', '')).toBe('Caf\u00E9.jpg')
})
it('rejects a name with no extension', () => {
expect(uploadFilename('photo', '')).toBeUndefined()
})
@@ -0,0 +1,68 @@
import { describe, it, expect, vi, afterEach } from 'vitest'
import { createIdleTimeoutStream, IdleTimeoutError } from '../src/idleTimeoutStream'
afterEach(() => vi.useRealTimers())
/** Resolve with the stream's error, or undefined when it ends cleanly. */
function outcome (stream: NodeJS.ReadableStream): Promise<Error | undefined> {
return new Promise(resolve => {
stream.on('data', () => {})
stream.on('error', resolve)
stream.on('end', () => resolve(undefined))
})
}
describe('createIdleTimeoutStream', () => {
it('drops a body that never starts', async () => {
vi.useFakeTimers()
const stream = createIdleTimeoutStream(1000)
const result = outcome(stream)
await vi.advanceTimersByTimeAsync(1000)
expect(await result).toBeInstanceOf(IdleTimeoutError)
})
it('keeps a slow but steady body flowing', async () => {
vi.useFakeTimers()
const stream = createIdleTimeoutStream(1000)
const result = outcome(stream)
for (let i = 0; i < 5; i++) {
stream.write(Buffer.alloc(1))
await vi.advanceTimersByTimeAsync(900)
}
stream.end()
expect(await result).toBeUndefined()
})
it('drops a body that trickles below the byte floor', async () => {
vi.useFakeTimers()
const stream = createIdleTimeoutStream(1000, 100)
const result = outcome(stream)
stream.write(Buffer.alloc(99))
await vi.advanceTimersByTimeAsync(1000)
expect(await result).toBeInstanceOf(IdleTimeoutError)
})
it('keeps a body that meets the byte floor in every interval', async () => {
vi.useFakeTimers()
const stream = createIdleTimeoutStream(1000, 100)
const result = outcome(stream)
for (let i = 0; i < 3; i++) {
stream.write(Buffer.alloc(50))
await vi.advanceTimersByTimeAsync(400)
stream.write(Buffer.alloc(50))
await vi.advanceTimersByTimeAsync(600)
}
stream.end()
expect(await result).toBeUndefined()
})
it('stops its timer when the body ends, so a small file is never judged by a partial interval', async () => {
vi.useFakeTimers()
const stream = createIdleTimeoutStream(1000, 100)
const result = outcome(stream)
stream.end(Buffer.alloc(10))
expect(await result).toBeUndefined()
await vi.advanceTimersByTimeAsync(5000)
expect(vi.getTimerCount()).toBe(0)
})
})
+15 -1
View File
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest'
import { fileType, formatSize, isUploadableType } from '../src/shared/upload'
import { fileType, formatSize, isUploadableName, isUploadableType } from '../src/shared/upload'
import { declaredLength, uploadTimestamp } from '../src/receive'
describe('isUploadableType', () => {
@@ -22,6 +22,20 @@ describe('isUploadableType', () => {
})
})
describe('isUploadableName', () => {
it('refuses an SVG extension whatever type the request declares', () => {
expect(isUploadableName('evil.svg')).toBe(false)
expect(isUploadableName('ipp_upload_evil.SVG')).toBe(false)
expect(isUploadableName('evil.svgz')).toBe(false)
})
it('accepts photo and video extensions, and leaves the finer check to Immich', () => {
expect(isUploadableName('IMG_0042.jpg')).toBe(true)
expect(isUploadableName('clip.mp4')).toBe(true)
expect(isUploadableName('my.svg.jpg')).toBe(true)
})
})
describe('fileType', () => {
it('keeps the type the browser gave', () => {
expect(fileType('IMG_0042.HEIC', 'image/heic')).toBe('image/heic')