v3: added site-wide categories, added admin category management, various visual fixes
All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 2m52s
All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 2m52s
This commit is contained in:
@@ -16,6 +16,20 @@ import {
|
||||
unfollowPlaylist,
|
||||
unfollowUser,
|
||||
} from "../services/follow-service.ts";
|
||||
import { getCategoryIdBySlug } from "../services/category-service.ts";
|
||||
|
||||
// Resolves the optional ?category=<slug> filter. Returns the matching category
|
||||
// id, or "missing" when a slug was given but matches nothing (so the feed comes
|
||||
// back empty rather than unfiltered), or undefined when no filter was requested.
|
||||
function resolveCategoryFilter(
|
||||
params: URLSearchParams,
|
||||
): string | "missing" | undefined {
|
||||
const slug = params.get("category");
|
||||
if (!slug) return undefined;
|
||||
return getCategoryIdBySlug(slug) ?? "missing";
|
||||
}
|
||||
|
||||
const EMPTY_FEED: { items: Dump[]; total: number } = { items: [], total: 0 };
|
||||
|
||||
const router = new Router({ prefix: "/api/follows" });
|
||||
|
||||
@@ -31,11 +45,10 @@ router.get("/status", authMiddleware, (ctx) => {
|
||||
// GET /api/follows/feed/users?page=&limit=
|
||||
router.get("/feed/users", authMiddleware, (ctx) => {
|
||||
const { page, limit } = parsePagination(ctx.request.url.searchParams);
|
||||
const { items, total } = getFollowedUsersDumpFeed(
|
||||
ctx.state.user.userId,
|
||||
page,
|
||||
limit,
|
||||
);
|
||||
const categoryId = resolveCategoryFilter(ctx.request.url.searchParams);
|
||||
const { items, total } = categoryId === "missing"
|
||||
? EMPTY_FEED
|
||||
: getFollowedUsersDumpFeed(ctx.state.user.userId, page, limit, categoryId);
|
||||
const data: PaginatedData<Dump> = {
|
||||
items,
|
||||
total,
|
||||
@@ -48,11 +61,15 @@ router.get("/feed/users", authMiddleware, (ctx) => {
|
||||
// GET /api/follows/feed/playlists?page=&limit=
|
||||
router.get("/feed/playlists", authMiddleware, (ctx) => {
|
||||
const { page, limit } = parsePagination(ctx.request.url.searchParams);
|
||||
const { items, total } = getFollowedPlaylistsDumpFeed(
|
||||
ctx.state.user.userId,
|
||||
page,
|
||||
limit,
|
||||
);
|
||||
const categoryId = resolveCategoryFilter(ctx.request.url.searchParams);
|
||||
const { items, total } = categoryId === "missing"
|
||||
? EMPTY_FEED
|
||||
: getFollowedPlaylistsDumpFeed(
|
||||
ctx.state.user.userId,
|
||||
page,
|
||||
limit,
|
||||
categoryId,
|
||||
);
|
||||
const data: PaginatedData<Dump> = {
|
||||
items,
|
||||
total,
|
||||
|
||||
Reference in New Issue
Block a user