fix: validate route params and reduce duplication
This commit is contained in:
@@ -30,16 +30,16 @@ export async function kijijiRoute(req: Request): Promise<Response> {
|
||||
location: reqUrl.searchParams.get("location") || undefined,
|
||||
category: reqUrl.searchParams.get("category") || undefined,
|
||||
keywords: reqUrl.searchParams.get("keywords") || undefined,
|
||||
sortBy: reqUrl.searchParams.get("sortBy") as
|
||||
sortBy: (reqUrl.searchParams.get("sortBy") as
|
||||
| "relevancy"
|
||||
| "date"
|
||||
| "price"
|
||||
| "distance"
|
||||
| undefined,
|
||||
sortOrder: reqUrl.searchParams.get("sortOrder") as
|
||||
| undefined) || undefined,
|
||||
sortOrder: (reqUrl.searchParams.get("sortOrder") as
|
||||
| "desc"
|
||||
| "asc"
|
||||
| undefined,
|
||||
| undefined) || undefined,
|
||||
maxPages,
|
||||
priceMin,
|
||||
priceMax,
|
||||
@@ -47,22 +47,14 @@ export async function kijijiRoute(req: Request): Promise<Response> {
|
||||
};
|
||||
|
||||
try {
|
||||
const items = hideUnstableResults
|
||||
? await fetchKijijiItems(
|
||||
SEARCH_QUERY,
|
||||
4, // 4 requests per second for faster scraping
|
||||
"https://www.kijiji.ca",
|
||||
searchOptions,
|
||||
{},
|
||||
{ hideUnstableResults: true },
|
||||
)
|
||||
: await fetchKijijiItems(
|
||||
SEARCH_QUERY,
|
||||
4, // 4 requests per second for faster scraping
|
||||
"https://www.kijiji.ca",
|
||||
searchOptions,
|
||||
{},
|
||||
);
|
||||
const items = await fetchKijijiItems(
|
||||
SEARCH_QUERY,
|
||||
4, // 4 requests per second for faster scraping
|
||||
"https://www.kijiji.ca",
|
||||
searchOptions,
|
||||
{},
|
||||
...(hideUnstableResults ? [{ hideUnstableResults: true }] : []),
|
||||
);
|
||||
|
||||
const isEmpty = hideUnstableResults
|
||||
? items.results.length === 0 && items.unstableResults.length === 0
|
||||
|
||||
Reference in New Issue
Block a user