mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-23 21:18:47 +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
84 lines
2.2 KiB
TypeScript
84 lines
2.2 KiB
TypeScript
import type { ImageTranscode, VideoTranscode } from '@shumai/dtos'
|
|
|
|
type Transcode = ImageTranscode | VideoTranscode
|
|
|
|
const WEB_IMAGE_EXTENSION_REGEX = /\.(png|jpe?g|webp|gif|svg|avif|bmp|ico)$/i
|
|
|
|
export function isImageFileName(filename?: string | null): boolean {
|
|
if (!filename) return false
|
|
return WEB_IMAGE_EXTENSION_REGEX.test(filename)
|
|
}
|
|
|
|
export function getBestTranscode(
|
|
transcodes: Transcode[] | undefined,
|
|
screenWidth: number,
|
|
): Transcode | null {
|
|
if (!transcodes || transcodes.length === 0) {
|
|
return null
|
|
}
|
|
|
|
// Sort by width descending to easily find largest available
|
|
const sorted = [...transcodes].sort((a, b) => {
|
|
const wA = a.width ?? 0
|
|
const wB = b.width ?? 0
|
|
return wB - wA // Descending width
|
|
})
|
|
|
|
// Find smallest width that is >= screenWidth
|
|
const suitable = sorted.filter((t) => (t.width ?? 0) >= screenWidth)
|
|
|
|
if (suitable.length > 0) {
|
|
// Sort suitable by width ASCENDING to find "smallest fit".
|
|
suitable.sort((a, b) => {
|
|
const wA = a.width ?? 0
|
|
const wB = b.width ?? 0
|
|
return wA - wB // Ascending
|
|
})
|
|
return suitable[0]
|
|
}
|
|
|
|
// If no candidate >= screenWidth, simply return the largest available (first in original sorted)
|
|
return sorted[0]
|
|
}
|
|
|
|
export function getVideoResolutionLabel(
|
|
transcode?: {
|
|
width?: number
|
|
height?: number
|
|
resolution?: string
|
|
} | null,
|
|
): string {
|
|
if (!transcode) return ''
|
|
|
|
if (transcode.resolution) {
|
|
return transcode.resolution
|
|
}
|
|
|
|
const width = transcode.width ?? 0
|
|
const height = transcode.height ?? 0
|
|
|
|
if (width > 0 && height > 0) {
|
|
const longSide = Math.max(width, height)
|
|
const shortSide = Math.min(width, height)
|
|
|
|
if (longSide >= 3840 || shortSide >= 2160) return '2160p'
|
|
if (longSide >= 2560 || shortSide >= 1440) return '1440p'
|
|
if (longSide >= 1920 || shortSide >= 1080) return '1080p'
|
|
if (longSide >= 1280 || shortSide >= 720) return '720p'
|
|
if (longSide >= 854 || shortSide >= 480) return '480p'
|
|
if (longSide >= 640 || shortSide >= 360) return '360p'
|
|
if (longSide >= 320 || shortSide >= 180) return '180p'
|
|
|
|
return `${shortSide}p`
|
|
}
|
|
|
|
if (height > 0) {
|
|
return `${height}p`
|
|
}
|
|
if (width > 0) {
|
|
return `${width}p`
|
|
}
|
|
|
|
return ''
|
|
}
|