2023-11-29 23:07:31 +00:00
|
|
|
import { fetchFeedData } from "@/lib/feed.ts";
|
2023-12-10 01:09:05 +00:00
|
|
|
import { type NextRequest, NextResponse } from "next/server";
|
2023-11-29 23:07:31 +00:00
|
|
|
|
2023-12-10 01:09:05 +00:00
|
|
|
export async function GET(req: NextRequest) {
|
|
|
|
const { filter, page = "0" } = req.nextUrl.searchParams as any as {
|
2023-11-29 23:07:31 +00:00
|
|
|
filter: "latest" | "day" | "week" | "month";
|
|
|
|
page: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
try {
|
|
|
|
// Define the limit of articles per page
|
|
|
|
const limit = 5;
|
|
|
|
|
|
|
|
// Calculate the `current` and `next` values based on the `page` parameter
|
|
|
|
const current = parseInt(page, 10) * limit;
|
|
|
|
const next = limit;
|
|
|
|
|
|
|
|
// Prepare the parameters for fetchFeedData
|
|
|
|
const queryParams = {
|
|
|
|
filter: filter ? { timerange: filter } : undefined,
|
|
|
|
next,
|
|
|
|
limit,
|
|
|
|
current,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Fetch data using the fetchFeedData function
|
|
|
|
const dataResponse = await fetchFeedData(queryParams);
|
|
|
|
|
2023-12-10 01:09:05 +00:00
|
|
|
return NextResponse.json(dataResponse);
|
2023-11-29 23:07:31 +00:00
|
|
|
} catch (error) {
|
2023-12-10 01:09:05 +00:00
|
|
|
return NextResponse.json({ error: "Internal Server Error" });
|
2023-11-29 23:07:31 +00:00
|
|
|
}
|
|
|
|
}
|