Some fixes

This commit is contained in:
2025-06-11 23:03:40 +09:00
parent 71d3f1912d
commit 6e2700fe3d
8 changed files with 423 additions and 193 deletions

View File

@ -512,13 +512,15 @@ app.get("/api/feeds", async (c) => {
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 { fetchActiveFeedsPaginated } = await import("./services/database.js");
const { fetchActiveFeedsPaginated } = await import(
"./services/database.js"
);
const pageNum = page ? Number.parseInt(page, 10) : 1;
const limitNum = limit ? Number.parseInt(limit, 10) : 10;
// Validate pagination parameters
if (Number.isNaN(pageNum) || pageNum < 1) {
return c.json({ error: "Invalid page number" }, 400);
@ -526,8 +528,12 @@ app.get("/api/feeds", async (c) => {
if (Number.isNaN(limitNum) || limitNum < 1 || limitNum > 100) {
return c.json({ error: "Invalid limit (must be between 1-100)" }, 400);
}
const result = await fetchActiveFeedsPaginated(pageNum, limitNum, category || undefined);
const result = await fetchActiveFeedsPaginated(
pageNum,
limitNum,
category || undefined,
);
return c.json(result);
} else {
// Original behavior for backward compatibility
@ -630,13 +636,15 @@ app.get("/api/episodes-with-feed-info", async (c) => {
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 { 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);
@ -644,12 +652,18 @@ app.get("/api/episodes-with-feed-info", async (c) => {
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);
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 { fetchEpisodesWithFeedInfo } = await import(
"./services/database.js"
);
const episodes = await fetchEpisodesWithFeedInfo();
return c.json({ episodes });
}