fix(sync): pin Dropbox source

This commit is contained in:
Christian Vidal Wolf
2026-05-21 13:53:12 +02:00
parent 9c0a7d18a0
commit cffd16acc7
2 changed files with 6 additions and 41 deletions
+5 -37
View File
@@ -1,7 +1,6 @@
import React, { useState, useMemo, useEffect } from 'react';
import * as XLSX from 'xlsx';
import { X } from 'lucide-react';
import defaultWorkbookUrl from '../data (3).xlsx?url';
import { cn } from './lib/utils';
import { AppState, ExcelRow, resolveColumnIndices, COLUMNS } from './types';
import { ColumnsProvider } from './contexts/ColumnsContext';
@@ -87,31 +86,6 @@ function readStoredBcSyncQueue(): BcSyncQueue {
}
}
async function loadWorkbookFromUrl(url: string) {
const response = await fetch(url, { cache: 'no-store' });
if (!response.ok) {
throw new Error(`HTTP ${response.status}`);
}
const arrayBuffer = await response.arrayBuffer();
if (arrayBuffer.byteLength < 100) {
throw new Error('File too small');
}
const wb = XLSX.read(arrayBuffer, { type: 'array' });
const wsname = wb.SheetNames[0];
const ws = wb.Sheets[wsname];
const allData = XLSX.utils.sheet_to_json<any[]>(ws, { header: 1 });
const rows = allData.slice(1);
const headers = allData.slice(0, 1)[0] || [];
return {
headers,
rows,
fileMeta: { rev: url, size: arrayBuffer.byteLength },
};
}
export default function App() {
const [session, setSession] = useState<AuthSession | null>(() => getStoredSession());
@@ -226,7 +200,7 @@ export default function App() {
if (isDev) {
const cacheBuster = `t_${Date.now()}`;
const fileUrl = `/dropbox-file/scl/fi/usa8me7ywgylrij2bt6hj/Data-Matrix.xlsx?rlkey=tsec8csrhye54u1fdvk15ped1&dl=1&${cacheBuster}=${Date.now()}`;
const fileUrl = `/api/dropbox-proxy?${cacheBuster}=${Date.now()}`;
console.log('Fetching Data-Matrix.xlsx from Dropbox (hard refresh)...');
try {
const response = await fetch(fileUrl, { cache: 'no-store' });
@@ -247,11 +221,8 @@ export default function App() {
rows = allData.slice(1);
fileMeta = { rev: 'dev', size: arrayBuffer.byteLength };
} catch (devErr) {
console.warn('Dropbox dev load failed, using bundled workbook fallback:', devErr);
const fallback = await loadWorkbookFromUrl(defaultWorkbookUrl);
allData = [fallback.headers, ...fallback.rows];
rows = fallback.rows;
fileMeta = fallback.fileMeta;
console.error('Dropbox dev load failed:', devErr);
throw devErr;
}
} else {
console.log('Fetching file info from Dropbox...');
@@ -280,11 +251,8 @@ export default function App() {
allData = XLSX.utils.sheet_to_json<any[]>(ws, { header: 1 });
rows = allData.slice(1);
} catch (prodErr) {
console.warn('Dropbox prod load failed, using bundled workbook fallback:', prodErr);
const fallback = await loadWorkbookFromUrl(defaultWorkbookUrl);
allData = [fallback.headers, ...fallback.rows];
rows = fallback.rows;
fileMeta = fallback.fileMeta;
console.error('Dropbox prod load failed:', prodErr);
throw prodErr;
}
}