feat(discover): add preview mode

This commit is contained in:
ItzCrazyKns
2025-05-30 08:35:15 +05:30
parent 117a683d9a
commit 740ff941a5

View File

@ -16,28 +16,43 @@ const topics = ['AI', 'tech']; /* TODO: Add UI to customize this */
export const GET = async (req: Request) => { export const GET = async (req: Request) => {
try { try {
const data = ( const params = new URL(req.url).searchParams;
await Promise.all([ const mode: 'normal' | 'preview' =
...new Array(articleWebsites.length * topics.length) (params.get('mode') as 'normal' | 'preview') || 'normal';
.fill(0)
.map(async (_, i) => { let data = [];
return (
await searchSearxng( if (mode === 'normal') {
`site:${articleWebsites[i % articleWebsites.length]} ${ data = (
topics[i % topics.length] await Promise.all([
}`, ...new Array(articleWebsites.length * topics.length)
{ .fill(0)
engines: ['bing news'], .map(async (_, i) => {
pageno: 1, return (
}, await searchSearxng(
) `site:${articleWebsites[i % articleWebsites.length]} ${
).results; topics[i % topics.length]
}), }`,
]) {
) engines: ['bing news'],
.map((result) => result) pageno: 1,
.flat() },
.sort(() => Math.random() - 0.5); )
).results;
}),
])
)
.map((result) => result)
.flat()
.sort(() => Math.random() - 0.5);
} else {
data = (
await searchSearxng(
`site:${articleWebsites[Math.floor(Math.random() * articleWebsites.length)]} ${topics[Math.floor(Math.random() * topics.length)]}`,
{ engines: ['bing news'], pageno: 1 },
)
).results;
}
return Response.json( return Response.json(
{ {