This commit is contained in:
2025-06-07 13:45:48 +09:00
parent d642b913ab
commit 9580740398
18 changed files with 936 additions and 1669 deletions

View File

@ -107,6 +107,88 @@ app.get("/", serveIndex);
app.get("/index.html", serveIndex);
// API endpoints for frontend
app.get("/api/episodes", async (c) => {
try {
const { fetchEpisodesWithArticles } = await import("./services/database.js");
const episodes = await fetchEpisodesWithArticles();
return c.json(episodes);
} catch (error) {
console.error("Error fetching episodes:", error);
return c.json({ error: "Failed to fetch episodes" }, 500);
}
});
app.get("/api/feeds", async (c) => {
try {
const { getAllFeedsIncludingInactive } = await import("./services/database.js");
const feeds = await getAllFeedsIncludingInactive();
return c.json(feeds);
} catch (error) {
console.error("Error fetching feeds:", error);
return c.json({ error: "Failed to fetch feeds" }, 500);
}
});
app.post("/api/feeds", async (c) => {
try {
const body = await c.req.json();
const { url } = body;
if (!url || typeof url !== 'string') {
return c.json({ error: "URL is required" }, 400);
}
const { addNewFeedUrl } = await import("./scripts/fetch_and_generate.js");
await addNewFeedUrl(url);
return c.json({ success: true, message: "Feed added successfully" });
} catch (error) {
console.error("Error adding feed:", error);
return c.json({ error: "Failed to add feed" }, 500);
}
});
app.delete("/api/feeds/:id", async (c) => {
try {
const feedId = c.req.param("id");
const { deleteFeed } = await import("./services/database.js");
const success = await deleteFeed(feedId);
if (!success) {
return c.json({ error: "Feed not found" }, 404);
}
return c.json({ success: true, message: "Feed deleted successfully" });
} catch (error) {
console.error("Error deleting feed:", error);
return c.json({ error: "Failed to delete feed" }, 500);
}
});
app.patch("/api/feeds/:id/toggle", async (c) => {
try {
const feedId = c.req.param("id");
const body = await c.req.json();
const { active } = body;
if (typeof active !== 'boolean') {
return c.json({ error: "Active status must be boolean" }, 400);
}
const { toggleFeedActive } = await import("./services/database.js");
const success = await toggleFeedActive(feedId, active);
if (!success) {
return c.json({ error: "Feed not found" }, 404);
}
return c.json({ success: true, message: "Feed status updated successfully" });
} catch (error) {
console.error("Error toggling feed:", error);
return c.json({ error: "Failed to update feed status" }, 500);
}
});
// Catch-all for SPA routing
app.get("*", serveIndex);