v3: added an "in collections" section to dump pages, listing the collections a dump belongs to
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
isCreateUrlDumpRequest,
|
||||
isUpdateDumpRequest,
|
||||
type PaginatedData,
|
||||
type Playlist,
|
||||
} from "../model/interfaces.ts";
|
||||
|
||||
import { authMiddleware } from "../middleware/auth.ts";
|
||||
@@ -30,6 +31,7 @@ import {
|
||||
} from "../services/dump-service.ts";
|
||||
import { getDumpVoters } from "../services/vote-service.ts";
|
||||
import { getRelatedDumps } from "../services/backlink-service.ts";
|
||||
import { getPlaylistsForDump } from "../services/playlist-service.ts";
|
||||
|
||||
const router = new Router({ prefix: "/api/dumps" });
|
||||
|
||||
@@ -128,6 +130,18 @@ router.get("/:dumpId/related", async (ctx) => {
|
||||
ctx.response.body = responseBody;
|
||||
});
|
||||
|
||||
router.get("/:dumpId/playlists", async (ctx) => {
|
||||
const requestingUserId = await parseOptionalAuth(ctx) ?? undefined;
|
||||
// Resolve through getDump so private dumps 404 for anyone but their owner.
|
||||
const dump = getDump(ctx.params.dumpId, requestingUserId);
|
||||
const playlists = getPlaylistsForDump(dump.id, requestingUserId);
|
||||
const responseBody: APIResponse<Playlist[]> = {
|
||||
success: true,
|
||||
data: playlists,
|
||||
};
|
||||
ctx.response.body = responseBody;
|
||||
});
|
||||
|
||||
router.get("/", async (ctx) => {
|
||||
const requestingUserId = await parseOptionalAuth(ctx) ?? undefined;
|
||||
const { page, limit } = parsePagination(ctx.request.url.searchParams);
|
||||
|
||||
@@ -382,6 +382,26 @@ export function getPlaylistMembershipsForDump(
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The playlists a dump appears in — the "in collections" counterpart to
|
||||
* backlinks. Privacy-filtered like `getRelatedDumps`: public playlists for
|
||||
* everyone, plus the requesting user's own private ones. Capped at 20 — a
|
||||
* small, bounded list of supporting context.
|
||||
*/
|
||||
export function getPlaylistsForDump(
|
||||
dumpId: string,
|
||||
requestingUserId?: string,
|
||||
): Playlist[] {
|
||||
const rows = db.prepare(
|
||||
`SELECT ${PLAYLIST_SELECT}
|
||||
INNER JOIN playlist_dumps pd ON pd.playlist_id = p.id
|
||||
WHERE pd.dump_id = ? AND (p.is_public = 1 OR p.user_id = ?)
|
||||
ORDER BY p.created_at DESC LIMIT 20;`,
|
||||
).all(dumpId, requestingUserId ?? "");
|
||||
|
||||
return rows.filter(isPlaylistRow).map(playlistRowToApi);
|
||||
}
|
||||
|
||||
export function getPlaylistImageInfo(
|
||||
idOrSlug: string,
|
||||
): { id: string; imageMime: string } | undefined {
|
||||
|
||||
Reference in New Issue
Block a user