fix(fetch): add proxy fallbacks and improved error logging for dropbox

This commit is contained in:
christian.vidal
2026-03-27 12:07:22 +01:00
parent 5d0a53731c
commit a5ac3ba359
+32 -10
View File
@@ -24,19 +24,36 @@ export default function App() {
useEffect(() => {
const loadDefaultData = async () => {
try {
// Use different proxies as fallbacks
const proxies = [
(url: string) => `https://api.allorigins.win/raw?url=${encodeURIComponent(url)}`,
(url: string) => `https://cors-anywhere.herokuapp.com/${url}`, // Often needs manual activation but we'll try
(url: string) => `https://thingproxy.freeboard.io/fetch/${url}`
];
const dropboxUrl = 'https://dl.dropboxusercontent.com/scl/fi/nkyabkq2jdwfudof2ovrl/Data-Matrix.xlsx?rlkey=1cz5fuabwipqqivihii7sybw0&st=io0g4wvb&dl=1';
setIsLoadingDefault(true);
setDefaultLoadError(null);
// Using allorigins proxy to avoid Dropbox CORS issues and improve reliability
const dropboxUrl = 'https://dl.dropboxusercontent.com/scl/fi/nkyabkq2jdwfudof2ovrl/Data-Matrix.xlsx?rlkey=1cz5fuabwipqqivihii7sybw0&st=io0g4wvb&dl=1';
const proxyUrl = `https://api.allorigins.win/raw?url=${encodeURIComponent(dropboxUrl)}`;
let lastError = null;
for (const getProxyUrl of proxies) {
try {
const proxyUrl = getProxyUrl(dropboxUrl);
console.log(`Attempting to fetch via: ${proxyUrl}`);
const response = await fetch(proxyUrl);
if (!response.ok) {
throw new Error(`Failed to fetch file: ${response.statusText}`);
throw new Error(`Proxy returned status ${response.status}: ${response.statusText}`);
}
const arrayBuffer = await response.arrayBuffer();
if (arrayBuffer.byteLength < 100) {
throw new Error("File too small, possibly empty or error page");
}
const wb = XLSX.read(arrayBuffer, { type: 'array' });
const wsname = wb.SheetNames[0];
const ws = wb.Sheets[wsname];
@@ -46,18 +63,23 @@ export default function App() {
setAppState({
headers: data[0],
data: data.slice(1),
fileName: 'Data-Matrix.xlsx (Auto-loaded Google Drive/Dropbox)',
fileName: 'Data-Matrix.xlsx (Cloud Sync)',
fileDate: new Date(),
hasUnsavedChanges: false
});
setActiveModule('descriptions');
setIsLoadingDefault(false);
return; // Success!
}
} catch (err) {
console.error('Error loading default data:', err);
setDefaultLoadError(err instanceof Error ? err.message : 'Unknown error');
} finally {
setIsLoadingDefault(false);
console.error(`Failed with proxy:`, err);
lastError = err;
}
}
// If we reach here, all proxies failed
setDefaultLoadError(lastError instanceof Error ? lastError.message : 'All connection attempts failed');
setIsLoadingDefault(false);
};
loadDefaultData();