mirror of
https://github.com/ItzCrazyKns/Perplexica.git
synced 2025-06-07 18:38:42 +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) => {
|
export const GET = async (req: Request) => {
|
||||||
try {
|
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([
|
await Promise.all([
|
||||||
...new Array(articleWebsites.length * topics.length)
|
...new Array(articleWebsites.length * topics.length)
|
||||||
.fill(0)
|
.fill(0)
|
||||||
@ -38,6 +45,14 @@ export const GET = async (req: Request) => {
|
|||||||
.map((result) => result)
|
.map((result) => result)
|
||||||
.flat()
|
.flat()
|
||||||
.sort(() => Math.random() - 0.5);
|
.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(
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user