mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 11:35:24 +02:00
feat: replace Vendor tab with BSR tracker
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { promises as fs } from 'fs';
|
||||
import path from 'path';
|
||||
import type { VercelRequest, VercelResponse } from '@vercel/node';
|
||||
|
||||
export default async function handler(req: VercelRequest, res: VercelResponse) {
|
||||
try {
|
||||
const filePath = path.join(process.cwd(), 'BSR.xlsx');
|
||||
|
||||
try {
|
||||
await fs.access(filePath);
|
||||
} catch {
|
||||
return res.status(404).json({ error: 'BSR data file not found' });
|
||||
}
|
||||
|
||||
const fileBuffer = await fs.readFile(filePath);
|
||||
|
||||
res.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
||||
res.setHeader('Content-Disposition', 'attachment; filename="BSR.xlsx"');
|
||||
res.setHeader('Cache-Control', 'public, max-age=3600');
|
||||
|
||||
// Convert Buffer to ArrayBuffer before sending for fetch compatibility on client
|
||||
res.send(fileBuffer);
|
||||
} catch (error) {
|
||||
console.error('Error serving BSR Excel file:', error);
|
||||
res.status(500).json({ error: 'Failed to serve BSR file' });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user