support flash

This commit is contained in:
Moon.eth
2026-08-03 15:28:51 +09:00
parent 1b14d94f6a
commit 7d16969f02
16 changed files with 599 additions and 9 deletions
+46
View File
@@ -0,0 +1,46 @@
import { describe, expect, it } from 'vitest'
import type { MediaAttachment } from '$lib/api/types'
import { flashAspectRatio, isFlashAttachment } from './flash'
function attachment(overrides: Partial<MediaAttachment> = {}): MediaAttachment {
return {
id: 'file-1',
type: 'unknown',
url: 'https://media.example.test/file.bin',
preview_url: null,
...overrides,
}
}
describe('Flash attachment detection', () => {
it('recognizes Pleroma MIME metadata and explicit Flash types', () => {
expect(
isFlashAttachment(
attachment({ pleroma: { mime_type: 'application/x-shockwave-flash' } }),
),
).toBe(true)
expect(isFlashAttachment(attachment({ type: 'flash' }))).toBe(true)
})
it('recognizes case-insensitive SWF paths despite query strings or fragments', () => {
expect(
isFlashAttachment(
attachment({ url: 'https://media.example.test/games/MOVIE.SWF?download=1#play' }),
),
).toBe(true)
expect(
isFlashAttachment(attachment({ url: 'https://media.example.test/movie.swf.png' })),
).toBe(false)
})
it('uses bounded intrinsic dimensions and a safe fallback', () => {
expect(
flashAspectRatio(
attachment({ meta: { original: { width: 1920, height: 1080 } } }),
),
).toBeCloseTo(16 / 9)
expect(
flashAspectRatio(attachment({ meta: { original: { width: 10000, height: 1 } } })),
).toBeCloseTo(4 / 3)
})
})