mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 13:05:24 +02:00
feat: Add UK inventory sync from Dropbox
- Create new API endpoint api/fetch-uk-inventory.ts - Add processUKInventoryExcel function in dataProcessor.ts - Update handleVendorStockFetch to load PANEU + UK in parallel - Configure Vite proxy for UK inventory endpoint - UK stock correctly populates 'uk' field in vendorStockMap
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import type { VercelRequest, VercelResponse } from '@vercel/node';
|
||||
|
||||
// UK Inventory from Dropbox (using dl=1 for direct download)
|
||||
const UK_INVENTORY_DROPBOX_URL = "https://www.dropbox.com/scl/fi/an1ldjmtej7tbt6fuh2ut/UK-Inventory.xlsx?rlkey=5h8e4st885bggibujk0b1lmm8&st=7vbagnwz&dl=1";
|
||||
|
||||
export default async function handler(req: VercelRequest, res: VercelResponse) {
|
||||
// CORS headers
|
||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
||||
res.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS');
|
||||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
|
||||
|
||||
if (req.method === 'OPTIONS') {
|
||||
return res.status(200).end();
|
||||
}
|
||||
|
||||
try {
|
||||
console.log('[fetch-uk-inventory] Fetching UK Inventory from Dropbox...');
|
||||
const response = await fetch(UK_INVENTORY_DROPBOX_URL, {
|
||||
cache: 'no-store',
|
||||
headers: {
|
||||
'Pragma': 'no-cache',
|
||||
'Cache-Control': 'no-cache'
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Dropbox responded with ${response.status}`);
|
||||
}
|
||||
|
||||
const buffer = await response.arrayBuffer();
|
||||
console.log('[fetch-uk-inventory] Successfully fetched UK Inventory Excel, size:', buffer.byteLength);
|
||||
|
||||
res.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
||||
res.status(200).send(Buffer.from(buffer));
|
||||
} catch (error: any) {
|
||||
console.error('[fetch-uk-inventory] Error:', error);
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user