fix(sync): handle special characters in filenames when downloading (#2694)

This commit is contained in:
Huang Xin
2025-12-12 02:20:27 +08:00
committed by GitHub
parent 0874fb0764
commit 34fd64c5c4
@@ -18,7 +18,18 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
}
if (req.method === 'GET') {
const { fileKey } = req.query;
let { fileKey } = req.query;
// Also parse fileKey directly from raw URL to handle special characters like & in filenames.
// because frameworks may incorrectly split parameters when the fileKey value contains
// encoded & (%26), treating it as a parameter separator.
if (req.url?.includes('fileKey=') && req.url?.includes('&')) {
const fileKeyFromUrl = req.url
.substring(req.url.indexOf('fileKey=') + 8)
.replace(/\+/g, '%20')
.replace(/&/g, '%26')
.replace(/=$/, '');
fileKey = decodeURIComponent(fileKeyFromUrl);
}
if (!fileKey || typeof fileKey !== 'string') {
return res.status(400).json({ error: 'Missing or invalid fileKey' });
}