fix: support gltf uploads with local preview
This commit is contained in:
@@ -1,8 +1,3 @@
|
||||
import { join } from 'path'
|
||||
import { existsSync } from 'fs'
|
||||
import { mkdir, writeFile, readFile, unlink, rm } from 'fs/promises'
|
||||
import { TMP_DIR } from '@/lib/constants'
|
||||
import { compressWithBlender } from '@/lib/blender'
|
||||
import { compressTextureBuffer } from '@/lib/texture-compression'
|
||||
import { classifyAssetCategory } from '@/lib/asset-classification'
|
||||
import type { ParsedFile, PreparedAssetSummary } from '@/lib/types'
|
||||
@@ -40,36 +35,11 @@ export async function prepareGitAssets({
|
||||
|
||||
if (pf.isModel) {
|
||||
modelFilename = pf.filename
|
||||
let modelCompressed = false
|
||||
|
||||
const tmpFolder = join(TMP_DIR, folderName)
|
||||
await mkdir(tmpFolder, { recursive: true })
|
||||
const tmpFilePath = join(tmpFolder, pf.filename)
|
||||
await writeFile(tmpFilePath, pf.buffer)
|
||||
|
||||
const stem = pf.filename.replace(/\.[^.]+$/, '')
|
||||
const compressedPath = join(tmpFolder, `${stem}_compressed.glb`)
|
||||
|
||||
try {
|
||||
const result = await compressWithBlender(tmpFilePath, compressedPath)
|
||||
|
||||
if (result.success && existsSync(compressedPath)) {
|
||||
content = await readFile(compressedPath)
|
||||
compressed = true
|
||||
modelCompressed = true
|
||||
await unlink(compressedPath).catch(() => {})
|
||||
} else {
|
||||
compressionError = result.error
|
||||
}
|
||||
} finally {
|
||||
await unlink(tmpFilePath).catch(() => {})
|
||||
await rm(tmpFolder, { recursive: true, force: true }).catch(() => {})
|
||||
}
|
||||
|
||||
assetSummaries.push({
|
||||
filename: pf.filename,
|
||||
kind: 'model',
|
||||
compressed: modelCompressed,
|
||||
compressed: false,
|
||||
})
|
||||
} else {
|
||||
const category = classifyAssetCategory(pf.filename)
|
||||
|
||||
Reference in New Issue
Block a user