feat(discover): add preview mode
This commit is contained in:
parent
117a683d9a
commit
740ff941a5
1 changed files with 37 additions and 22 deletions
|
|
@ -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(
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue