mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 16:25:23 +02:00
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
import type { VercelRequest, VercelResponse } from '@vercel/node';
|
|||
|
|
|
||
|
|
const ADS_DROPBOX_URL = "https://www.dropbox.com/scl/fi/wng8tep7awhvzd65amwad/Ads-Weekly.xlsx?rlkey=kcmoq8dxgibsb2eb8zz47xvyo&st=z02m4w3g&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-ads] Fetching Ads from Dropbox...');
|
||
|
|
const response = await fetch(ADS_DROPBOX_URL);
|
||
|
|
|
||
|
|
if (!response.ok) {
|
||
|
|
throw new Error(`Dropbox responded with ${response.status}`);
|
||
|
|
}
|
||
|
|
|
||
|
|
const buffer = await response.arrayBuffer();
|
||
|
|
console.log('[fetch-ads] Successfully fetched Ads 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-ads] Error:', error);
|
||
|
|
res.status(500).json({ error: error.message });
|
||
|
|
}
|
||
|
|
}
|