This commit is contained in:
2025-06-09 08:44:59 +09:00
parent abe4f18273
commit 27004f0cef
3 changed files with 279 additions and 21 deletions

View File

@ -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);