From 525b4c10897120ae7c5995141aef1417a6ee3927 Mon Sep 17 00:00:00 2001 From: odweta Date: Mon, 7 Sep 2026 16:44:40 +0200 Subject: [PATCH] add: export in JSON --- app/src/search.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/app/src/search.js b/app/src/search.js index 598ab89..58d8e15 100644 --- a/app/src/search.js +++ b/app/src/search.js @@ -1,5 +1,4 @@ // TODO: unit tests for business logic -// TODO: export in JSON const cheerio = require("cheerio"); @@ -35,7 +34,7 @@ async function handleSearch(req, res) { format: "json" }); - const response = await fetch( + const reposnse = await fetch( `${searxngUrl}/search?${params}`, { headers: { @@ -43,9 +42,18 @@ async function handleSearch(req, res) { } } ); + const data = await reposnse.json(); - const data = await response.json(); - res.json(filterJson(data.results || [])); + const filteredresults = filterJson(data.results || []); + + // Send the result as a downloadable JSON file + res.setHeader("Content-Type", "application/json; charset=utf-8"); + res.setHeader( + "Content-Disposition", + 'attachment; filename="output.json"' + ); + + return res.send(JSON.stringify(filteredresults, null, 2)); } catch (error) { console.error("[SEARCH.JS] " + error); res.status(500).send("

Search failed!
See the console for the error.

");