fix: /export defaults to JSON, ?format=txt for plain text

This commit is contained in:
2026-06-11 16:32:19 +04:00
parent e3c4c738aa
commit e0cbf4bf35
+3 -3
View File
@@ -86,7 +86,7 @@ function createEntriesRouter({ q }) {
}); });
// GET /api/v1/entries/export — агрегированный список CIDR // GET /api/v1/entries/export — агрегированный список CIDR
// ?format=json → JSON, иначе text/plain // По умолчанию JSON. ?format=txt → text/plain.
// Только для админа. // Только для админа.
router.get('/export', async (req, res) => { router.get('/export', async (req, res) => {
try { try {
@@ -105,8 +105,8 @@ function createEntriesRouter({ q }) {
const cidrs = await q.getExportCIDRs(companyId); const cidrs = await q.getExportCIDRs(companyId);
const aggregated = aggregateCIDRs(cidrs); const aggregated = aggregateCIDRs(cidrs);
const isJson = req.query.format === 'json'; const isText = req.query.format === 'txt';
if (isJson) { if (!isText) {
res.setHeader('Content-Type', 'application/json; charset=utf-8'); res.setHeader('Content-Type', 'application/json; charset=utf-8');
const fname = (req.query.filename || 'white-list.json').replace(/[^\w\-_. ]/g, '_'); const fname = (req.query.filename || 'white-list.json').replace(/[^\w\-_. ]/g, '_');
const disp = req.query.view === '1' ? 'inline' : 'attachment'; const disp = req.query.view === '1' ? 'inline' : 'attachment';