fix: robust handling of Dropbox URLs in proxy with query params

This commit is contained in:
Christian Vidal Wolf
2026-01-16 14:20:08 +01:00
parent 17eb5484c1
commit 599b0fa8e2
+15 -2
View File
@@ -27,9 +27,22 @@ export default async function handler(req: VercelRequest, res: VercelResponse) {
const requestPath = req.url || ''; const requestPath = req.url || '';
const dropboxPath = requestPath.replace(/^\/api\/dropbox/, ''); // e.g. /scl/fi/xyz?dl=1 const dropboxPath = requestPath.replace(/^\/api\/dropbox/, ''); // e.g. /scl/fi/xyz?dl=1
const targetUrl = `https://www.dropbox.com${dropboxPath}`; let targetUrl = `https://www.dropbox.com${dropboxPath}`;
console.log(`Proxying to: ${targetUrl}`); // Ensure dl=1 is present to force download
if (targetUrl.includes('?')) {
if (!targetUrl.includes('dl=1')) {
targetUrl = targetUrl.replace('dl=0', 'dl=1');
if (!targetUrl.includes('dl=1')) {
targetUrl += '&dl=1';
}
}
} else {
targetUrl += '?dl=1';
}
console.log(`[Proxy] Incoming: ${req.url}`);
console.log(`[Proxy] Target: ${targetUrl}`);
const response = await fetch(targetUrl); const response = await fetch(targetUrl);