mirror of
https://github.com/christianvidalwolf-prog/Craze-Data-check.git
synced 2026-08-03 13:55:23 +02:00
fix: use raw fetch for Dropbox API instead of SDK, add better error logging
This commit is contained in:
+14
-12
@@ -54,6 +54,7 @@ export default function App() {
|
||||
const isDev = import.meta.env.DEV;
|
||||
|
||||
let rows: any[][];
|
||||
let allData: any[][];
|
||||
let fileMeta = { rev: '', size: 0 };
|
||||
|
||||
if (isDev) {
|
||||
@@ -67,8 +68,8 @@ export default function App() {
|
||||
const wb = XLSX.read(arrayBuffer, { type: 'array' });
|
||||
const wsname = wb.SheetNames[0];
|
||||
const ws = wb.Sheets[wsname];
|
||||
const data = XLSX.utils.sheet_to_json<any[]>(ws, { header: 1 });
|
||||
rows = data.slice(1);
|
||||
allData = XLSX.utils.sheet_to_json<any[]>(ws, { header: 1 });
|
||||
rows = allData.slice(1);
|
||||
fileMeta = { rev: 'dev', size: arrayBuffer.byteLength };
|
||||
} else {
|
||||
console.log('Fetching file info from Dropbox...');
|
||||
@@ -87,12 +88,12 @@ export default function App() {
|
||||
const wb = XLSX.read(arrayBuffer, { type: 'array' });
|
||||
const wsname = wb.SheetNames[0];
|
||||
const ws = wb.Sheets[wsname];
|
||||
const data = XLSX.utils.sheet_to_json<any[]>(ws, { header: 1 });
|
||||
rows = data.slice(1);
|
||||
allData = XLSX.utils.sheet_to_json<any[]>(ws, { header: 1 });
|
||||
rows = allData.slice(1);
|
||||
}
|
||||
|
||||
if (rows.length > 0) {
|
||||
const rawHeaders = (data: any[]) => data[0];
|
||||
const headers = allData.slice(0, 1)[0];
|
||||
|
||||
console.log('Syncing Excel data to Supabase...');
|
||||
const syncRes = await fetch('/api/dropbox-sync', {
|
||||
@@ -105,7 +106,8 @@ export default function App() {
|
||||
const syncResult = await syncRes.json();
|
||||
console.log('Supabase sync result:', syncResult);
|
||||
} else {
|
||||
console.warn('Supabase sync failed, falling back to direct Excel data');
|
||||
const errorText = await syncRes.text();
|
||||
console.warn('Supabase sync failed:', syncRes.status, errorText);
|
||||
}
|
||||
|
||||
console.log('Fetching synced data from Supabase...');
|
||||
@@ -123,7 +125,7 @@ export default function App() {
|
||||
|
||||
return finalRow.map((val: any, idx: number) => {
|
||||
if (val === undefined || val === null || val === '') return val;
|
||||
const header = (rawHeaders[idx] || '').toLowerCase();
|
||||
const header = (headers[idx] || '').toLowerCase();
|
||||
|
||||
if ((header.includes('id') || header.includes('no') || header.includes('code') ||
|
||||
header.includes('art.') || header.includes('barcode') || header.includes('article')) &&
|
||||
@@ -149,12 +151,12 @@ export default function App() {
|
||||
});
|
||||
});
|
||||
|
||||
const asinIdx = (rawHeaders(rows) as string[]).findIndex((h: string) =>
|
||||
const asinIdx = (headers as string[]).findIndex((h: string) =>
|
||||
String(h).toLowerCase().trim() === 'asin'
|
||||
);
|
||||
|
||||
setAppState({
|
||||
headers: rawHeaders(rows),
|
||||
headers: headers,
|
||||
data: processedRows,
|
||||
fileName: 'Data-Matrix.xlsx (Cloud Sync)',
|
||||
fileDate: new Date(),
|
||||
@@ -194,13 +196,13 @@ export default function App() {
|
||||
const data = XLSX.utils.sheet_to_json<any[]>(ws, { header: 1 });
|
||||
|
||||
if (data.length > 0) {
|
||||
const rawHeaders = data[0];
|
||||
const headers = data[0];
|
||||
const rawRows = data.slice(1);
|
||||
|
||||
const processedRows = rawRows.map(row => {
|
||||
return row.map((val, idx) => {
|
||||
if (val === undefined || val === null || val === '') return val;
|
||||
const header = (rawHeaders[idx] || '').toLowerCase();
|
||||
const header = (headers[idx] || '').toLowerCase();
|
||||
|
||||
if (header.includes('id') || header.includes('no') || header.includes('code') ||
|
||||
header.includes('art.') || header.includes('barcode') || header.includes('article')) {
|
||||
@@ -239,7 +241,7 @@ export default function App() {
|
||||
});
|
||||
|
||||
setAppState({
|
||||
headers: rawHeaders,
|
||||
headers: headers,
|
||||
data: processedRows,
|
||||
fileName: file.name,
|
||||
fileDate: new Date(),
|
||||
|
||||
Reference in New Issue
Block a user