mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-23 16:18:39 +00:00
* feat(transcode): add 3D asset support and turntable viewer * perf(turntable): stream file via Bun.file and increase upload timeout * feat(turntable): increase upload timeout to 15m to support 5GB uploads * fix(webui): align 3D model viewer layout and full-width control bar with video viewer * feat(webui): unify 3D viewer bottom bar and redesign cyclic ruler slider - Place RulerSlider in single row with playback and zoom controls, centered with max 320px width - Flank RulerSlider with minus and plus buttons to step angle by 15° - Redesign RulerSlider with fixed center indicator and moving cyclic track with continuous 360° wrapping - Render major ticks longer at 60° intervals without numeric text labels on track - Display floating degree tooltip above center indicator only during dragging * fix(webui): prevent RulerSlider from collapsing to 0px width in control bar - Use flex layout with flex-1 on left and right clusters to preserve center cluster width - Enforce min-w-[140px] and w-full on RulerSlider - Fix tooltip positioning and remove outer overflow-hidden * feat(webui): snap RulerSlider track directly to discrete 15° ticks during drag * fix(webui): prevent ruler snap-back caused by floating point second truncation - Use Math.round instead of Math.floor in secondToDegree to avoid 0.999996 dropping to previous frame - Ensure final dragDegree is committed on pointer up * fix(webui): fix arrow key frame rounding and duplicate event bubbling - Use Math.round instead of Math.floor for keyboard arrow frame navigation in ModelViewer - Add e.stopPropagation() to RulerSlider keyboard events to prevent duplicate bubbling to window listener * feat(webui): redesign RulerSlider with encapsulated step buttons and capsule pill track * feat(webui): make RulerSlider responsive on mobile and remove bottom bar reset button * fix(webui): load 3d video directly without poster and invert drag rotation to counterclockwise * fix(webui): fix 3d asset viewer frame seeking and drag jitter * feat(transcode): show 3D asset poster preview immediately after render start * fix(viewer): synchronize 3D turntable playback via frame callback to prevent skipped degrees * fix(viewer): handle touchpad zoom gestures and prevent page zoom in 3D viewer * fix(viewer): eliminate 3D model rotation jitter at 345 degrees * fix(share): watermark 3D asset turntable video on share links * fix(share): preserve video transcode resolution on watermarked share links * fix(viewer): download original 3D model file instead of rendered turntable MP4
110 lines
5.1 KiB
TypeScript
110 lines
5.1 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { isImageFileName, getBestTranscode, getVideoResolutionLabel } from './media'
|
|
|
|
describe('isImageFileName', () => {
|
|
it('identifies web-supported image formats as images', () => {
|
|
expect(isImageFileName('photo.png')).toBe(true)
|
|
expect(isImageFileName('photo.jpg')).toBe(true)
|
|
expect(isImageFileName('photo.jpeg')).toBe(true)
|
|
expect(isImageFileName('photo.webp')).toBe(true)
|
|
expect(isImageFileName('animation.gif')).toBe(true)
|
|
expect(isImageFileName('icon.svg')).toBe(true)
|
|
expect(isImageFileName('image.avif')).toBe(true)
|
|
expect(isImageFileName('bitmap.bmp')).toBe(true)
|
|
expect(isImageFileName('favicon.ico')).toBe(true)
|
|
})
|
|
|
|
it('handles uppercase extensions and paths/urls with query params', () => {
|
|
expect(isImageFileName('PHOTO.PNG')).toBe(true)
|
|
expect(isImageFileName('PHOTO.JPEG')).toBe(true)
|
|
expect(isImageFileName('/path/to/my-image.webp')).toBe(true)
|
|
})
|
|
|
|
it('does not treat non-web-renderable or non-image files as images', () => {
|
|
expect(isImageFileName('design.psd')).toBe(false)
|
|
expect(isImageFileName('photo.raw')).toBe(false)
|
|
expect(isImageFileName('document.pdf')).toBe(false)
|
|
expect(isImageFileName('video.mp4')).toBe(false)
|
|
expect(isImageFileName('archive.zip')).toBe(false)
|
|
expect(isImageFileName('notes.txt')).toBe(false)
|
|
expect(isImageFileName('')).toBe(false)
|
|
expect(isImageFileName(null)).toBe(false)
|
|
expect(isImageFileName(undefined)).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('getBestTranscode', () => {
|
|
it('returns null if transcodes array is empty or undefined', () => {
|
|
expect(getBestTranscode(undefined, 800)).toBeNull()
|
|
expect(getBestTranscode([], 800)).toBeNull()
|
|
})
|
|
|
|
it('picks smallest transcode >= screenWidth or falls back to largest', () => {
|
|
const transcodes = [
|
|
{ id: '1', width: 400, height: 300, url: '', key: '', size: 100 },
|
|
{ id: '2', width: 800, height: 600, url: '', key: '', size: 200 },
|
|
{ id: '3', width: 1200, height: 900, url: '', key: '', size: 300 },
|
|
]
|
|
expect(getBestTranscode(transcodes, 700)?.width).toBe(800)
|
|
expect(getBestTranscode(transcodes, 1500)?.width).toBe(1200)
|
|
})
|
|
})
|
|
|
|
describe('getVideoResolutionLabel', () => {
|
|
it('preserves explicit resolution when present', () => {
|
|
expect(getVideoResolutionLabel({ width: 854, height: 480, resolution: '480p' })).toBe('480p')
|
|
expect(getVideoResolutionLabel({ width: 480, height: 854, resolution: '480p' })).toBe('480p')
|
|
expect(getVideoResolutionLabel({ width: 1920, height: 1080, resolution: '1080p' })).toBe(
|
|
'1080p',
|
|
)
|
|
})
|
|
|
|
it('derives resolution from long side for portrait legacy transcodes without explicit resolution', () => {
|
|
// 4K portrait
|
|
expect(getVideoResolutionLabel({ width: 2160, height: 3840 })).toBe('2160p')
|
|
// 2K / 1440p portrait
|
|
expect(getVideoResolutionLabel({ width: 1440, height: 2560 })).toBe('1440p')
|
|
// 1080p portrait
|
|
expect(getVideoResolutionLabel({ width: 1080, height: 1920 })).toBe('1080p')
|
|
// 720p portrait
|
|
expect(getVideoResolutionLabel({ width: 720, height: 1280 })).toBe('720p')
|
|
// 480p portrait
|
|
expect(getVideoResolutionLabel({ width: 480, height: 854 })).toBe('480p')
|
|
// 360p portrait
|
|
expect(getVideoResolutionLabel({ width: 360, height: 640 })).toBe('360p')
|
|
// 180p portrait
|
|
expect(getVideoResolutionLabel({ width: 180, height: 320 })).toBe('180p')
|
|
})
|
|
|
|
it('derives resolution from long side for landscape legacy transcodes without explicit resolution', () => {
|
|
expect(getVideoResolutionLabel({ width: 3840, height: 2160 })).toBe('2160p')
|
|
expect(getVideoResolutionLabel({ width: 2560, height: 1440 })).toBe('1440p')
|
|
expect(getVideoResolutionLabel({ width: 1920, height: 1080 })).toBe('1080p')
|
|
expect(getVideoResolutionLabel({ width: 1280, height: 720 })).toBe('720p')
|
|
expect(getVideoResolutionLabel({ width: 854, height: 480 })).toBe('480p')
|
|
expect(getVideoResolutionLabel({ width: 640, height: 360 })).toBe('360p')
|
|
expect(getVideoResolutionLabel({ width: 320, height: 180 })).toBe('180p')
|
|
})
|
|
|
|
it('derives resolution correctly for square and non-16:9 transcodes without explicit resolution', () => {
|
|
// 1080p square (e.g. 1080x1080 3D turntable or square video)
|
|
expect(getVideoResolutionLabel({ width: 1080, height: 1080 })).toBe('1080p')
|
|
// 720p square
|
|
expect(getVideoResolutionLabel({ width: 720, height: 720 })).toBe('720p')
|
|
// 480p square
|
|
expect(getVideoResolutionLabel({ width: 480, height: 480 })).toBe('480p')
|
|
// 1080p 4:3
|
|
expect(getVideoResolutionLabel({ width: 1440, height: 1080 })).toBe('1080p')
|
|
// 720p 4:3
|
|
expect(getVideoResolutionLabel({ width: 960, height: 720 })).toBe('720p')
|
|
})
|
|
|
|
it('falls back to short side or single dimension for non-standard sizes', () => {
|
|
expect(getVideoResolutionLabel({ width: 200, height: 100 })).toBe('100p')
|
|
expect(getVideoResolutionLabel({ height: 720 })).toBe('720p')
|
|
expect(getVideoResolutionLabel({ width: 500 })).toBe('500p')
|
|
expect(getVideoResolutionLabel(null)).toBe('')
|
|
expect(getVideoResolutionLabel(undefined)).toBe('')
|
|
})
|
|
})
|