Corrigiu template do IFC cloud

X-Lovable-Edit-ID: edt-589aa454-694a-4be9-8271-5db7f5303b9c
Co-authored-by: Reifonas <211114984+Reifonas@users.noreply.github.com>
This commit is contained in:
gpt-engineer-app[bot]
2026-05-14 11:43:05 +00:00
+54 -3
View File
@@ -7,6 +7,28 @@ import { toast } from 'sonner';
import { getSupportedExtension, convertToGLB, ACCEPTED_EXTENSIONS } from '@/lib/convertToGLB'; import { getSupportedExtension, convertToGLB, ACCEPTED_EXTENSIONS } from '@/lib/convertToGLB';
import { convertIFCtoGLB } from '@/lib/convertIFC'; import { convertIFCtoGLB } from '@/lib/convertIFC';
/**
* Normaliza URLs comuns para apontar ao binário direto.
* - Dropbox: força dl=1
* - OneDrive (1drv.ms / onedrive.live.com): força download=1
*/
function normalizeCloudUrl(input: string): string {
try {
const u = new URL(input);
if (/(^|\.)dropbox\.com$/.test(u.hostname)) {
u.searchParams.set('dl', '1');
return u.toString();
}
if (/(^|\.)1drv\.ms$|onedrive\.live\.com$/.test(u.hostname)) {
u.searchParams.set('download', '1');
return u.toString();
}
return input;
} catch {
return input;
}
}
const Index = () => { const Index = () => {
const navigate = useNavigate(); const navigate = useNavigate();
const fileInputRef = useRef<HTMLInputElement>(null); const fileInputRef = useRef<HTMLInputElement>(null);
@@ -63,18 +85,47 @@ const Index = () => {
}, [setModel]); }, [setModel]);
const handleLoadCloud = useCallback(async () => { const handleLoadCloud = useCallback(async () => {
const url = window.prompt('URL do modelo (GLB · OBJ · STL · IFC):', 'https://'); const DEFAULT_URL = 'https://store.tracksteel.com.br/demo.ifc';
if (!url) return; 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); setLoadingCloud(true);
try { try {
// Normalizações automáticas para hosts comuns
const url = normalizeCloudUrl(raw.trim());
const fileName = url.split('/').pop()?.split('?')[0] || 'modelo-cloud'; const fileName = url.split('/').pop()?.split('?')[0] || 'modelo-cloud';
const ext = getSupportedExtension(fileName); const ext = getSupportedExtension(fileName);
if (!ext) { if (!ext) {
toast.error('URL deve apontar para .GLB, .OBJ, .STL ou .IFC'); toast.error('URL deve apontar para .GLB, .OBJ, .STL ou .IFC');
return; return;
} }
const response = await fetch(url, { mode: 'cors' });
let response = await fetch(url, { mode: 'cors' });
if (!response.ok) throw new Error(`HTTP ${response.status}`); 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(); const buffer = await response.arrayBuffer();
let blob: Blob; let blob: Blob;