feat: sync Excel data to Supabase on load - detect new Dropbox files automatically

This commit is contained in:
Christian Vidal Wolf
2026-04-10 10:54:50 +02:00
parent 077e78513c
commit 90e60017da
6 changed files with 400 additions and 64 deletions
+27 -14
View File
@@ -1,23 +1,36 @@
// Vercel serverless function — proxies the Dropbox file server-side (no CORS)
const Dropbox = require('dropbox').Dropbox;
export default async function handler(req, res) {
const fileUrl =
'https://dl.dropboxusercontent.com/scl/fi/nkyabkq2jdwfudof2ovrl/Data-Matrix.xlsx' +
'?rlkey=1cz5fuabwipqqivihii7sybw0&st=io0g4wvb&dl=1';
if (req.method === 'GET' && req.query.info === '1') {
const DBX = new Dropbox({
accessToken: process.env.DROPBOX_ACCESS_TOKEN
});
try {
const fileInfo = await DBX.filesGetInfo({ path: '/Data-Matrix.xlsx' });
return res.json({
rev: fileInfo.result.rev,
size: fileInfo.result.size,
server_modified: fileInfo.result.server_modified
});
} catch (err) {
return res.status(500).json({ error: err.message });
}
}
const DBX = new Dropbox({
accessToken: process.env.DROPBOX_ACCESS_TOKEN
});
try {
const upstream = await fetch(fileUrl, {
headers: { 'User-Agent': 'Mozilla/5.0' },
});
if (!upstream.ok) {
return res.status(upstream.status).send(`Dropbox error: ${upstream.status}`);
}
const buffer = await upstream.arrayBuffer();
const upstream = await DBX.filesDownload({ path: '/Data-Matrix.xlsx' });
const buffer = Buffer.from(upstream.result.fileBinary);
res.setHeader('Content-Type', 'application/octet-stream');
res.setHeader('Cache-Control', 'no-store');
res.send(Buffer.from(buffer));
res.send(buffer);
} catch (err) {
console.error('Dropbox error:', err);
res.status(500).send('Proxy error: ' + err.message);
}
}