mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 13:05:24 +02:00
feat: auto-load Traffic data from Dropbox on app startup
- api/fetch-traffic.ts: New endpoint to fetch Traffic Weekly.xlsx from Dropbox - App.tsx: Added handleTrafficFetch function and auto-fetch on initialization
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import type { VercelRequest, VercelResponse } from '@vercel/node';
|
||||
|
||||
const TRAFFIC_DROPBOX_URL = "https://www.dropbox.com/scl/fi/9cenju8djxav9z6q5if6m/Traffic-Weekly.xlsx?rlkey=r2oaixmnvzq6nnjuus0uowa6l&st=r7knws3r&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-traffic] Fetching Traffic from Dropbox...');
|
||||
const response = await fetch(TRAFFIC_DROPBOX_URL);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Dropbox responded with ${response.status}`);
|
||||
}
|
||||
|
||||
const buffer = await response.arrayBuffer();
|
||||
console.log('[fetch-traffic] Successfully fetched Traffic 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-traffic] Error:', error);
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user