v0.5.10: /export — attachment default, ?view=1 inline, ?filename=custom

This commit is contained in:
2026-06-02 14:49:50 +03:00
parent 72e021acfe
commit 51a003e078
4 changed files with 26 additions and 8 deletions
+11 -2
View File
@@ -14,11 +14,20 @@ function createRouter() {
router.get('/export', async (req, res) => {
const token = api.token(req);
const companyQuery = req.query.company ? '?company=' + parseInt(req.query.company, 10) : '';
// Прокидываем query-параметры в API
const params = new URLSearchParams();
if (req.query.company) params.set('company', req.query.company);
if (req.query.client_id) params.set('client_id', req.query.client_id);
const qs = params.toString();
const companyQuery = qs ? '?' + qs : '';
try {
const r = await api.get('/api/v1/entries/export' + companyQuery, token);
res.set('Content-Type', 'text/plain; charset=utf-8');
res.set('Content-Disposition', 'inline; filename="whitelist.txt"');
// ?view=1 → inline (просмотр), иначе → attachment (скачивание)
// ?filename=X → своё имя, по умолчанию white-list.txt
const fname = req.query.filename || 'white-list.txt';
const disp = req.query.view === '1' ? 'inline' : 'attachment';
res.set('Content-Disposition', disp + '; filename="' + fname + '"');
res.send(r.data);
} catch (e) {
res.status(500).send('Ошибка экспорта: ' + e.message);