fix: support gltf uploads with local preview
This commit is contained in:
@@ -3,6 +3,13 @@
|
||||
import { useState, useCallback } from 'react'
|
||||
import type { FolderEntry } from '@/lib/client-types'
|
||||
|
||||
function revokeEntryUrls(entry: FolderEntry) {
|
||||
const urls = new Set<string>()
|
||||
if (entry.modelUrl) urls.add(entry.modelUrl)
|
||||
Object.values(entry.assetUrls || {}).forEach((url) => urls.add(url))
|
||||
urls.forEach((url) => URL.revokeObjectURL(url))
|
||||
}
|
||||
|
||||
export function useFolderEntries() {
|
||||
const [entries, setEntries] = useState<FolderEntry[]>([])
|
||||
|
||||
@@ -13,7 +20,7 @@ export function useFolderEntries() {
|
||||
const removeEntry = useCallback((index: number) => {
|
||||
setEntries((prev) => {
|
||||
const entry = prev[index]
|
||||
if (entry?.modelUrl) URL.revokeObjectURL(entry.modelUrl)
|
||||
if (entry) revokeEntryUrls(entry)
|
||||
return prev.filter((_, i) => i !== index)
|
||||
})
|
||||
}, [])
|
||||
@@ -21,7 +28,7 @@ export function useFolderEntries() {
|
||||
const resetEntries = useCallback(() => {
|
||||
setEntries((prev) => {
|
||||
prev.forEach((f) => {
|
||||
if (f.modelUrl) URL.revokeObjectURL(f.modelUrl)
|
||||
revokeEntryUrls(f)
|
||||
})
|
||||
return []
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user