Update
This commit is contained in:
31
server.ts
31
server.ts
@ -627,11 +627,32 @@ app.get("/api/episode-with-source/:episodeId", async (c) => {
|
||||
|
||||
app.get("/api/episodes-with-feed-info", async (c) => {
|
||||
try {
|
||||
const { fetchEpisodesWithFeedInfo } = await import(
|
||||
"./services/database.js"
|
||||
);
|
||||
const episodes = await fetchEpisodesWithFeedInfo();
|
||||
return c.json({ episodes });
|
||||
const page = c.req.query("page");
|
||||
const limit = c.req.query("limit");
|
||||
const category = c.req.query("category");
|
||||
|
||||
// If pagination parameters are provided, use paginated endpoint
|
||||
if (page || limit) {
|
||||
const { fetchEpisodesWithFeedInfoPaginated } = await import("./services/database.js");
|
||||
const pageNum = page ? Number.parseInt(page, 10) : 1;
|
||||
const limitNum = limit ? Number.parseInt(limit, 10) : 20;
|
||||
|
||||
// Validate pagination parameters
|
||||
if (Number.isNaN(pageNum) || pageNum < 1) {
|
||||
return c.json({ error: "Invalid page number" }, 400);
|
||||
}
|
||||
if (Number.isNaN(limitNum) || limitNum < 1 || limitNum > 100) {
|
||||
return c.json({ error: "Invalid limit (must be between 1-100)" }, 400);
|
||||
}
|
||||
|
||||
const result = await fetchEpisodesWithFeedInfoPaginated(pageNum, limitNum, category || undefined);
|
||||
return c.json(result);
|
||||
} else {
|
||||
// Original behavior for backward compatibility
|
||||
const { fetchEpisodesWithFeedInfo } = await import("./services/database.js");
|
||||
const episodes = await fetchEpisodesWithFeedInfo();
|
||||
return c.json({ episodes });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error fetching episodes with feed info:", error);
|
||||
return c.json({ error: "Failed to fetch episodes with feed info" }, 500);
|
||||
|
Reference in New Issue
Block a user