add: export in JSON

This commit is contained in:
odweta
2026-09-07 16:44:40 +02:00
parent 5781d0e0d9
commit 525b4c1089
+12 -4
View File
@@ -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("<p><b>Search failed!<br>See the console for the error.</b></p>");