mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-25 08:19:06 +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
210 lines
6.1 KiB
TypeScript
210 lines
6.1 KiB
TypeScript
import { isRawImage } from './raw'
|
|
|
|
export type ProxyType = 'image' | 'video' | 'audio' | 'pdf' | '3d'
|
|
|
|
export function is3dModel(mediaType?: string | null, filename?: string | null): boolean {
|
|
const lowerMediaType = mediaType?.toLowerCase() || ''
|
|
const lowerFilename = filename?.toLowerCase() || ''
|
|
|
|
const modelExtensions = [
|
|
'.glb',
|
|
'.gltf',
|
|
'.usd',
|
|
'.usda',
|
|
'.usdc',
|
|
'.usdz',
|
|
'.fbx',
|
|
'.obj',
|
|
'.stl',
|
|
'.dae',
|
|
]
|
|
if (modelExtensions.some((ext) => lowerFilename.endsWith(ext))) {
|
|
return true
|
|
}
|
|
|
|
if (
|
|
lowerMediaType.startsWith('model/') ||
|
|
lowerMediaType === 'model/gltf-binary' ||
|
|
lowerMediaType === 'model/gltf+json' ||
|
|
lowerMediaType === 'model/obj' ||
|
|
lowerMediaType === 'model/stl' ||
|
|
lowerMediaType === 'model/vnd.usdz+zip' ||
|
|
lowerMediaType === 'model/vnd.collada+xml'
|
|
) {
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
export function isOfficeDocument(mediaType?: string | null, filename?: string | null): boolean {
|
|
const lowerMediaType = mediaType?.toLowerCase() || ''
|
|
const lowerFilename = filename?.toLowerCase() || ''
|
|
|
|
if (
|
|
lowerMediaType === 'application/msword' ||
|
|
lowerMediaType === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' ||
|
|
lowerMediaType === 'application/vnd.ms-excel' ||
|
|
lowerMediaType === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ||
|
|
lowerMediaType === 'application/vnd.ms-powerpoint' ||
|
|
lowerMediaType ===
|
|
'application/vnd.openxmlformats-officedocument.presentationml.presentation' ||
|
|
lowerMediaType === 'application/vnd.oasis.opendocument.text' ||
|
|
lowerMediaType === 'application/vnd.oasis.opendocument.spreadsheet' ||
|
|
lowerMediaType === 'application/vnd.oasis.opendocument.presentation' ||
|
|
lowerMediaType === 'application/rtf' ||
|
|
lowerMediaType === 'text/rtf'
|
|
) {
|
|
return true
|
|
}
|
|
|
|
const officeExtensions = [
|
|
'.doc',
|
|
'.docx',
|
|
'.xls',
|
|
'.xlsx',
|
|
'.ppt',
|
|
'.pptx',
|
|
'.odt',
|
|
'.ods',
|
|
'.odp',
|
|
'.rtf',
|
|
]
|
|
return officeExtensions.some((ext) => lowerFilename.endsWith(ext))
|
|
}
|
|
|
|
export function isHtmlDocument(mediaType?: string | null, filename?: string | null): boolean {
|
|
const lowerMediaType = mediaType?.toLowerCase() || ''
|
|
const lowerFilename = filename?.toLowerCase() || ''
|
|
|
|
return (
|
|
lowerMediaType === 'text/html' ||
|
|
lowerFilename.endsWith('.html') ||
|
|
lowerFilename.endsWith('.htm')
|
|
)
|
|
}
|
|
|
|
export function isMarkdownDocument(mediaType?: string | null, filename?: string | null): boolean {
|
|
const lowerMediaType = mediaType?.toLowerCase() || ''
|
|
const lowerFilename = filename?.toLowerCase() || ''
|
|
|
|
return (
|
|
lowerMediaType === 'text/markdown' ||
|
|
lowerMediaType === 'text/x-markdown' ||
|
|
lowerFilename.endsWith('.md') ||
|
|
lowerFilename.endsWith('.markdown')
|
|
)
|
|
}
|
|
|
|
export function isCsvDocument(mediaType?: string | null, filename?: string | null): boolean {
|
|
const lowerMediaType = mediaType?.toLowerCase() || ''
|
|
const lowerFilename = filename?.toLowerCase() || ''
|
|
|
|
return lowerMediaType === 'text/csv' || lowerFilename.endsWith('.csv')
|
|
}
|
|
|
|
export function getProxyType(
|
|
mediaType?: string | null,
|
|
filename?: string | null,
|
|
): ProxyType | null {
|
|
const lowerMediaType = mediaType?.toLowerCase() || ''
|
|
const lowerFilename = filename?.toLowerCase() || ''
|
|
|
|
if (
|
|
lowerMediaType.startsWith('image/') ||
|
|
lowerFilename.endsWith('.psd') ||
|
|
isRawImage(lowerFilename)
|
|
)
|
|
return 'image'
|
|
if (lowerMediaType.startsWith('video/')) return 'video'
|
|
if (lowerMediaType.startsWith('audio/')) return 'audio'
|
|
|
|
if (
|
|
lowerMediaType === 'application/pdf' ||
|
|
lowerMediaType === 'text/plain' ||
|
|
lowerFilename.endsWith('.pdf') ||
|
|
lowerFilename.endsWith('.txt') ||
|
|
isCsvDocument(mediaType, filename) ||
|
|
isMarkdownDocument(mediaType, filename) ||
|
|
isHtmlDocument(mediaType, filename) ||
|
|
isOfficeDocument(mediaType, filename)
|
|
) {
|
|
return 'pdf'
|
|
}
|
|
|
|
if (is3dModel(mediaType, filename)) {
|
|
return '3d'
|
|
}
|
|
|
|
return null
|
|
}
|
|
|
|
const PNG_SIGNATURE = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]
|
|
|
|
export function detectSupportedMimeType(buffer: Uint8Array): string | null {
|
|
if (startsWithAscii(buffer, 0, '8BPS')) {
|
|
return 'image/vnd.adobe.photoshop'
|
|
}
|
|
if (startsWith(buffer, [0xff, 0xd8, 0xff])) {
|
|
return buffer[3] === 0xf7 ? null : 'image/jpeg'
|
|
}
|
|
if (startsWith(buffer, PNG_SIGNATURE)) {
|
|
return isPng(buffer) && !isAnimatedPng(buffer) ? 'image/png' : null
|
|
}
|
|
if (startsWithAscii(buffer, 0, 'GIF')) {
|
|
return 'image/gif'
|
|
}
|
|
if (startsWithAscii(buffer, 0, 'RIFF') && startsWithAscii(buffer, 8, 'WEBP')) {
|
|
return 'image/webp'
|
|
}
|
|
if (startsWithAscii(buffer, 4, 'ftyp')) {
|
|
return 'video/mp4'
|
|
}
|
|
return null
|
|
}
|
|
|
|
function isPng(buffer: Uint8Array): boolean {
|
|
return (
|
|
buffer.length >= 16 &&
|
|
readUint32Be(buffer, PNG_SIGNATURE.length) === 13 &&
|
|
startsWithAscii(buffer, 12, 'IHDR')
|
|
)
|
|
}
|
|
|
|
function isAnimatedPng(buffer: Uint8Array): boolean {
|
|
let offset = PNG_SIGNATURE.length
|
|
while (offset + 8 <= buffer.length) {
|
|
const chunkLength = readUint32Be(buffer, offset)
|
|
const chunkTypeOffset = offset + 4
|
|
if (startsWithAscii(buffer, chunkTypeOffset, 'acTL')) return true
|
|
if (startsWithAscii(buffer, chunkTypeOffset, 'IDAT')) return false
|
|
|
|
const nextOffset = offset + 8 + chunkLength + 4
|
|
if (nextOffset <= offset || nextOffset > buffer.length) return false
|
|
offset = nextOffset
|
|
}
|
|
return false
|
|
}
|
|
|
|
function readUint32Be(buffer: Uint8Array, offset: number): number {
|
|
return (
|
|
(buffer[offset] ?? 0) * 0x1000000 +
|
|
((buffer[offset + 1] ?? 0) << 16) +
|
|
((buffer[offset + 2] ?? 0) << 8) +
|
|
(buffer[offset + 3] ?? 0)
|
|
)
|
|
}
|
|
|
|
function startsWith(buffer: Uint8Array, bytes: number[]): boolean {
|
|
if (buffer.length < bytes.length) return false
|
|
return bytes.every((byte, index) => buffer[index] === byte)
|
|
}
|
|
|
|
function startsWithAscii(buffer: Uint8Array, offset: number, text: string): boolean {
|
|
if (buffer.length < offset + text.length) return false
|
|
for (let index = 0; index < text.length; index++) {
|
|
if (buffer[offset + index] !== text.charCodeAt(index)) return false
|
|
}
|
|
return true
|
|
}
|