Move collection description rendering to JSON (#6944)

* First pass, moving collection description rendering to JSON

* tsc

* docs

* refactor

* test
This commit is contained in:
Tom Moor
2024-05-25 18:17:19 -04:00
committed by GitHub
parent d51267b8bc
commit f103d73b48
15 changed files with 225 additions and 81 deletions

View File

@@ -1,13 +1,21 @@
import { colorPalette } from "@shared/utils/collections";
import Collection from "@server/models/Collection";
import { DocumentHelper } from "@server/models/helpers/DocumentHelper";
import { APIContext } from "@server/types";
export default async function presentCollection(
ctx: APIContext | undefined,
collection: Collection
) {
const asData = !ctx || Number(ctx?.headers["x-api-version"] ?? 0) >= 3;
export default function presentCollection(collection: Collection) {
return {
id: collection.id,
url: collection.url,
urlId: collection.urlId,
name: collection.name,
description: collection.description,
data: asData ? await DocumentHelper.toJSON(collection) : undefined,
description: asData ? undefined : collection.description,
sort: collection.sort,
icon: collection.icon,
index: collection.index,