mirror of
https://github.com/ItzCrazyKns/Perplexica.git
synced 2025-06-07 10:28:37 +00:00
feat(discover): add preview mode
This commit is contained in:
@ -16,7 +16,14 @@ const topics = ['AI', 'tech']; /* TODO: Add UI to customize this */
|
||||
|
||||
export const GET = async (req: Request) => {
|
||||
try {
|
||||
const data = (
|
||||
const params = new URL(req.url).searchParams;
|
||||
const mode: 'normal' | 'preview' =
|
||||
(params.get('mode') as 'normal' | 'preview') || 'normal';
|
||||
|
||||
let data = [];
|
||||
|
||||
if (mode === 'normal') {
|
||||
data = (
|
||||
await Promise.all([
|
||||
...new Array(articleWebsites.length * topics.length)
|
||||
.fill(0)
|
||||
@ -38,6 +45,14 @@ export const GET = async (req: Request) => {
|
||||
.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(
|
||||
{
|
||||
|
Reference in New Issue
Block a user