v4: playlists have categories of their own — a set apart from the dumps', which admins manage on /manage under "Playlist categories", next to "Dump categories". Each category now has a kind, dump or playlist, its slug and name unique within its kind only; migration 0025 rebuilds categories with the column, every existing one becoming a dump category with its dumps, and adds playlist_categories. A playlist's owner files it under any of them in the create and edit forms, and it shows them as chips on its card and its page, each leading to /playlists/<slug>.
/playlists is the new page of every public playlist, newest first (GET /api/playlists), and /playlists/<slug> a playlist category's, with a menu of the categories, linked from the user menu as "All playlists"; `playlists` is reserved as a dump category's slug, and one that had it is renamed. A profile's Playlists tab narrows to a playlist category with the same menu as its Dumps tab (?category=), and so do the Dumps and Playlists tabs of /search, each with its own kind (category and playlistCategory for GET /api/search), another tab dropping it. The category service takes the kind throughout, so a dump can't be filed under a playlist category nor the other way round, and categoryJoin is the one filter join the dump, follow and playlist services share. useCategories(kind) gives one kind's set from the one fetch, CategoryChips replaces the chips the dump card and page each drew, useCategoryFilter keeps a list to its category as the socket brings more, and useCategorySelection holds a form's picked categories. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,13 +1,17 @@
|
||||
/**
|
||||
* Serves the categories dumps are filed under, and changes them for those with
|
||||
* `category:manage`. A category's feed is `GET /api/dumps?category=:slug`.
|
||||
* Serves the categories dumps and playlists are filed under, a set for each
|
||||
* kind, and changes them for those with `category:manage`. A dump category's
|
||||
* feed is `GET /api/dumps?category=:slug`, a playlist category's
|
||||
* `GET /api/playlists?category=:slug`.
|
||||
*
|
||||
* - `GET /api/categories` — public. Answers every category, in order.
|
||||
* - `POST /api/categories` — permission `category:manage`. Creates a category.
|
||||
* - `GET /api/categories` — public. Answers every category of both kinds, by
|
||||
* kind, then in order.
|
||||
* - `POST /api/categories` — permission `category:manage`. Creates a category
|
||||
* of the kind it names.
|
||||
* - `PUT /api/categories/:id` — permission `category:manage`. Updates a
|
||||
* category.
|
||||
* - `DELETE /api/categories/:id` — permission `category:manage`. Deletes a
|
||||
* category; its dumps stay.
|
||||
* category; its dumps or playlists stay.
|
||||
*
|
||||
* @module
|
||||
*/
|
||||
|
||||
@@ -79,7 +79,7 @@ router.get("/feed", authMiddleware, (ctx) => {
|
||||
throw new APIException(400, "from must be users or playlists");
|
||||
}
|
||||
const { page, limit } = parsePagination(params);
|
||||
const categoryId = resolveCategoryFilter(params);
|
||||
const categoryId = resolveCategoryFilter("dump", params);
|
||||
const userId = ctx.state.user.userId;
|
||||
const { items, hasMore } = categoryId === "missing"
|
||||
? EMPTY_FEED
|
||||
|
||||
@@ -3,12 +3,17 @@
|
||||
* playlist's id; its page reads it by its path, through
|
||||
* `GET /api/users/:key/playlists/:slug`.
|
||||
*
|
||||
* - `POST /api/playlists` — signed in. Creates a playlist.
|
||||
* - `GET /api/playlists?category=&page=&limit=` — public. Answers a page of
|
||||
* every public playlist, newest first, or only those in the playlist
|
||||
* category at `category`, which 404s when there is none.
|
||||
* - `POST /api/playlists` — signed in. Creates a playlist, filed under the
|
||||
* playlist categories it names.
|
||||
* - `GET /api/playlists/:playlistId` — optional sign-in. Answers a playlist
|
||||
* with the dumps the caller may see in it. A private one 404s but for its
|
||||
* owner.
|
||||
* - `PUT /api/playlists/:playlistId` — signed in, as its owner or with
|
||||
* `playlist:moderate`. Updates its title, slug, description and visibility.
|
||||
* `playlist:moderate`. Updates its title, slug, description, visibility and
|
||||
* categories.
|
||||
* A new slug keeps the old one as an alias, 3 times a day at most but for
|
||||
* those with `playlist:moderate`.
|
||||
* - `DELETE /api/playlists/:playlistId` — signed in, as its owner or with
|
||||
@@ -32,7 +37,7 @@
|
||||
|
||||
import { Router } from "@oak/oak";
|
||||
import { authenticateMedia, parseOptionalAuth } from "../lib/auth.ts";
|
||||
import { type APIResponse } from "../../shared/api.ts";
|
||||
import { type APIResponse, type PaginatedData } from "../../shared/api.ts";
|
||||
import { APIException } from "../lib/api-exception.ts";
|
||||
import {
|
||||
isCreatePlaylistRequest,
|
||||
@@ -49,6 +54,7 @@ import {
|
||||
getEditablePlaylist,
|
||||
getPlaylist,
|
||||
getPlaylistImageInfo,
|
||||
listPublicPlaylists,
|
||||
removeDumpFromPlaylist,
|
||||
reorderPlaylist,
|
||||
setPlaylistImage,
|
||||
@@ -60,6 +66,8 @@ import {
|
||||
validateImageUpload,
|
||||
} from "../lib/upload.ts";
|
||||
import { PLAYLIST_IMAGES_DIR } from "../config.ts";
|
||||
import { parsePagination } from "../lib/pagination.ts";
|
||||
import { getCategoryBySlug } from "../services/category-service.ts";
|
||||
|
||||
/**
|
||||
* Mounted by `api/main.ts` behind the error, Open Graph and CORS middleware.
|
||||
@@ -69,6 +77,19 @@ const router: Router<AuthState> = new Router<AuthState>({
|
||||
prefix: "/api/playlists",
|
||||
});
|
||||
|
||||
router.get("/", (ctx) => {
|
||||
const params = ctx.request.url.searchParams;
|
||||
const { page, limit } = parsePagination(params);
|
||||
const slug = params.get("category");
|
||||
const categoryId = slug ? getCategoryBySlug("playlist", slug).id : undefined;
|
||||
const { items, hasMore } = listPublicPlaylists(page, limit, categoryId);
|
||||
const responseBody: APIResponse<PaginatedData<Playlist>> = {
|
||||
success: true,
|
||||
data: { items, hasMore },
|
||||
};
|
||||
ctx.response.body = responseBody;
|
||||
});
|
||||
|
||||
router.post("/", authMiddleware, async (ctx) => {
|
||||
const body: unknown = await ctx.request.body.json();
|
||||
if (!isCreatePlaylistRequest(body)) {
|
||||
|
||||
@@ -3,9 +3,11 @@
|
||||
* Only the dumps are paged. Private dumps and playlists are found only by
|
||||
* their owner.
|
||||
*
|
||||
* - `GET /api/search?q=&page=&limit=` — optional sign-in. Answers a page of the
|
||||
* matching dumps with their total, and up to 20 matching users and
|
||||
* playlists. A blank `q` finds nothing.
|
||||
* - `GET /api/search?q=&page=&limit=&category=&playlistCategory=` — optional
|
||||
* sign-in. Answers a page of the matching dumps with their total, and up to
|
||||
* 20 matching users and playlists. A blank `q` finds nothing. `category`
|
||||
* keeps the dumps in that dump category, `playlistCategory` the playlists in
|
||||
* that playlist category; a slug that names none finds nothing.
|
||||
*
|
||||
* @module
|
||||
*/
|
||||
@@ -16,6 +18,7 @@ import { parsePagination } from "../lib/pagination.ts";
|
||||
import { searchDumps } from "../services/dump-service.ts";
|
||||
import { searchUsersGlobal } from "../services/user-service.ts";
|
||||
import { searchPlaylists } from "../services/playlist-service.ts";
|
||||
import { resolveCategoryFilter } from "../services/category-service.ts";
|
||||
import type { APIResponse } from "../../shared/api.ts";
|
||||
import type { SearchResults } from "../../shared/search.ts";
|
||||
|
||||
@@ -44,14 +47,19 @@ router.get("/", async (ctx) => {
|
||||
return;
|
||||
}
|
||||
|
||||
const { items: dumpItems, total: dumpTotal } = searchDumps(
|
||||
q,
|
||||
page,
|
||||
limit,
|
||||
requestingUserId,
|
||||
const dumpCategoryId = resolveCategoryFilter("dump", params);
|
||||
const playlistCategoryId = resolveCategoryFilter(
|
||||
"playlist",
|
||||
params,
|
||||
"playlistCategory",
|
||||
);
|
||||
const { items: dumpItems, total: dumpTotal } = dumpCategoryId === "missing"
|
||||
? { items: [], total: 0 }
|
||||
: searchDumps(q, page, limit, requestingUserId, dumpCategoryId);
|
||||
const users = searchUsersGlobal(q, 20);
|
||||
const playlists = searchPlaylists(q, 20, requestingUserId);
|
||||
const playlists = playlistCategoryId === "missing"
|
||||
? []
|
||||
: searchPlaylists(q, 20, requestingUserId, playlistCategoryId);
|
||||
|
||||
const responseBody: APIResponse<SearchResults> = {
|
||||
success: true,
|
||||
|
||||
@@ -19,8 +19,9 @@
|
||||
* - `GET /api/users/:key/upvoted?page=&limit=&category=` — optional sign-in.
|
||||
* Answers a page of the dumps they upvoted, private ones only to
|
||||
* themselves, optionally in one category.
|
||||
* - `GET /api/users/:key/playlists?page=&limit=` — optional sign-in. Answers a
|
||||
* page of the playlists they made, the private ones only to themselves.
|
||||
* - `GET /api/users/:key/playlists?page=&limit=&category=` — optional
|
||||
* sign-in. Answers a page of the playlists they made, the private ones only
|
||||
* to themselves, optionally in one playlist category.
|
||||
* - `GET /api/users/:key/playlists/:slug` — optional sign-in. Answers their
|
||||
* playlist whose slug is or was `slug`, with its current slug and the dumps
|
||||
* the caller may see; a private one 404s but for its owner.
|
||||
@@ -163,7 +164,7 @@ router.get("/:key/dumps", async (ctx) => {
|
||||
const requestingUserId = await parseOptionalAuth(ctx);
|
||||
const params = ctx.request.url.searchParams;
|
||||
const { page, limit } = parsePagination(params);
|
||||
const categoryId = resolveCategoryFilter(params);
|
||||
const categoryId = resolveCategoryFilter("dump", params);
|
||||
const includePrivate = requestingUserId === user.id;
|
||||
const { items, hasMore } = categoryId === "missing"
|
||||
? { items: [], hasMore: false }
|
||||
@@ -190,7 +191,7 @@ router.get("/:key/upvoted", async (ctx) => {
|
||||
const requestingUserId = await parseOptionalAuth(ctx);
|
||||
const params = ctx.request.url.searchParams;
|
||||
const { page, limit } = parsePagination(params);
|
||||
const categoryId = resolveCategoryFilter(params);
|
||||
const categoryId = resolveCategoryFilter("dump", params);
|
||||
const { items, hasMore } = categoryId === "missing"
|
||||
? { items: [], hasMore: false }
|
||||
: getVotedDumpsByUser(user.id, page, limit, requestingUserId, categoryId);
|
||||
@@ -204,13 +205,12 @@ router.get("/:key/upvoted", async (ctx) => {
|
||||
router.get("/:key/playlists", async (ctx) => {
|
||||
const user = resolveUserKey(ctx.params.key);
|
||||
const requestingUserId = await parseOptionalAuth(ctx);
|
||||
const { page, limit } = parsePagination(ctx.request.url.searchParams);
|
||||
const { items, hasMore } = listPlaylistsByUser(
|
||||
user.id,
|
||||
requestingUserId,
|
||||
page,
|
||||
limit,
|
||||
);
|
||||
const params = ctx.request.url.searchParams;
|
||||
const { page, limit } = parsePagination(params);
|
||||
const categoryId = resolveCategoryFilter("playlist", params);
|
||||
const { items, hasMore } = categoryId === "missing"
|
||||
? { items: [], hasMore: false }
|
||||
: listPlaylistsByUser(user.id, requestingUserId, page, limit, categoryId);
|
||||
const responseBody: APIResponse<PaginatedData<Playlist>> = {
|
||||
success: true,
|
||||
data: { items, hasMore },
|
||||
|
||||
Reference in New Issue
Block a user