mirror of
https://git.shipoclu.com/moon/plspace.git
synced 2026-08-13 02:42:30 +00:00
support flash
This commit is contained in:
@@ -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)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user