diff --git a/src/server/routes/discovery.ts b/src/server/routes/discovery.ts index ed4948a..5ae4758 100644 --- a/src/server/routes/discovery.ts +++ b/src/server/routes/discovery.ts @@ -1,9 +1,11 @@ import { Hono } from "hono"; import { + getPopularItemsByTags, getPopularSetups, getRecentGlobalItems, getTrendingCategories, } from "../services/discovery.service.ts"; +import { withImageUrls } from "../services/storage.service.ts"; type Env = { Variables: { db?: any } }; @@ -35,4 +37,23 @@ app.get("/categories", async (c) => { return c.json(result); }); +app.get("/popular-items", async (c) => { + const db = c.get("db"); + const tagsParam = c.req.query("tags") || ""; + const limitParam = c.req.query("limit"); + const tagNames = tagsParam + .split(",") + .map((t) => t.trim()) + .filter(Boolean); + const limit = limitParam ? Math.min(Number.parseInt(limitParam, 10), 50) : 24; + + if (tagNames.length === 0) { + return c.json({ items: [] }); + } + + const results = await getPopularItemsByTags(db, tagNames, limit); + const enriched = await withImageUrls(results); + return c.json({ items: enriched }); +}); + export { app as discoveryRoutes };