diff --git a/src/pages/Index.tsx b/src/pages/Index.tsx index b1f2dd5..ac1f499 100644 --- a/src/pages/Index.tsx +++ b/src/pages/Index.tsx @@ -63,72 +63,7 @@ const Index = () => { } }, [setModel]); - const handleLoadCloud = useCallback(async () => { - const DEFAULT_URL = 'https://store.tracksteel.com.br/demo.ifc'; - const raw = window.prompt( - 'URL do modelo (GLB · OBJ · STL · IFC).\nDica: Dropbox use ?dl=1 · OneDrive ?download=1 · FileBrowser /api/raw/', - DEFAULT_URL, - ); - if (!raw) return; - setLoadingCloud(true); - try { - // Normalizações automáticas para hosts comuns - const url = normalizeCloudUrl(raw.trim()); - const fileName = url.split('/').pop()?.split('?')[0] || 'modelo-cloud'; - const ext = getSupportedExtension(fileName); - if (!ext) { - toast.error('URL deve apontar para .GLB, .OBJ, .STL ou .IFC'); - return; - } - - let response = await fetch(url, { mode: 'cors' }); - if (!response.ok) throw new Error(`HTTP ${response.status}`); - - // Detecta servidores que retornam HTML em vez do binário (ex.: FileBrowser SPA) - let ct = response.headers.get('content-type') || ''; - if (ct.includes('text/html')) { - // Fallback: tenta endpoint /api/raw/ do FileBrowser - try { - const u = new URL(url); - if (!u.pathname.startsWith('/api/raw/')) { - const fbUrl = `${u.origin}/api/raw${u.pathname}${u.search}`; - const r2 = await fetch(fbUrl, { mode: 'cors' }); - if (r2.ok) { - response = r2; - ct = r2.headers.get('content-type') || ''; - } - } - } catch {} - } - if (ct.includes('text/html')) { - toast.error('O servidor devolveu uma página HTML, não o arquivo. Use o link DIRETO do arquivo (ex.: FileBrowser → /api/raw/arquivo.ifc).'); - return; - } - - const buffer = await response.arrayBuffer(); - - let blob: Blob; - let outName = fileName; - let outSize = buffer.byteLength; - if (ext === 'glb') { - blob = new Blob([buffer], { type: 'model/gltf-binary' }); - } else if (ext === 'ifc') { - const r = await convertIFCtoGLB(buffer, fileName); - blob = r.blob; outName = r.fileName; outSize = r.fileSize; - } else { - const r = await convertToGLB(buffer, ext, fileName); - blob = r.blob; outName = r.fileName; outSize = r.fileSize; - } - const blobUrl = URL.createObjectURL(blob); - setModel({ fileName: outName, fileSize: outSize, url: blobUrl }); - toast.success(`"${outName}" carregado da nuvem (RAM)`); - } catch (err) { - console.error(err); - toast.error('Falha ao carregar da nuvem (verifique URL/CORS)'); - } finally { - setLoadingCloud(false); - } - }, [setModel]); + // Carregar da Nuvem agora é encapsulado em const handleLoadDemoIFC = useCallback(async () => { setLoadingDemoIFC(true);