Co-authored-by: Reifonas <211114984+Reifonas@users.noreply.github.com>
This commit is contained in:
gpt-engineer-app[bot]
2026-05-14 11:40:41 +00:00
parent 8be546adc6
commit 6459f4df18
+32 -3
View File
@@ -63,18 +63,47 @@ const Index = () => {
}, [setModel]);
const handleLoadCloud = useCallback(async () => {
const url = window.prompt('URL do modelo (GLB · OBJ · STL · IFC):', 'https://');
if (!url) return;
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/<arquivo>',
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;
}
const response = await fetch(url, { mode: 'cors' });
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;