Changes
Co-authored-by: Reifonas <211114984+Reifonas@users.noreply.github.com>
This commit is contained in:
+32
-3
@@ -63,18 +63,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;
|
||||||
|
|||||||
Reference in New Issue
Block a user