Files
outline/server/presenters/collection.ts
T
Tom Moor 7f00defd62 feat: Add archive and deletion reasons (#13784)
* feat: Add reasons for archived and deleted documents

* feat: Add deprecation reasons to archived collections

* fix: Refine deprecation reason display for readers

* feat: Accept reasons when archiving or deleting

* Support reasons in archive and delete MCP tools

* Fix placeholder after clearing content editable text

* Keep the caret before content editable placeholders

* Remove test

* feat: Add archive reasons to the confirmation dialog
2026-09-18 21:09:35 -04:00

83 lines
2.6 KiB
TypeScript

import { Hour } from "@shared/utils/time";
import type Collection from "@server/models/Collection";
import { DocumentHelper } from "@server/models/helpers/DocumentHelper";
import type { APIContext } from "@server/types";
import presentUser from "./user";
type Options = {
/** Whether to render the collection's public fields. */
isPublic?: boolean;
/** The root share ID when presenting a shared collection. */
shareId?: string;
/** Whether to include the updatedAt timestamp. */
includeUpdatedAt?: boolean;
/** Always include the markdown description in the payload. */
includeText?: boolean;
/** Always include the data of the collection in the payload. */
includeData?: boolean;
};
export default async function presentCollection(
ctx: APIContext | undefined,
collection: Collection,
options: Options = {}
) {
const asData = !ctx || Number(ctx?.headers["x-api-version"] ?? 0) >= 3;
const res: Record<string, unknown> = {
id: collection.id,
url: collection.path,
urlId: collection.urlId,
name: collection.name,
data:
options.includeData === false
? undefined
: asData || options.includeData
? await DocumentHelper.toJSON(
collection,
options.isPublic
? {
signedUrls: Hour.seconds,
teamId: collection.teamId,
internalUrlBase: `/s/${options.shareId}`,
}
: undefined
)
: undefined,
description:
!asData || options.includeText ? collection.description : undefined,
sort: collection.sort,
icon: collection.icon,
color: collection.color,
createdAt: collection.createdAt,
updatedAt: collection.updatedAt,
archivedBy: undefined,
};
if (options.isPublic && !options.includeUpdatedAt) {
delete res.updatedAt;
}
if (!options.isPublic) {
res.index = collection.index;
res.sharing = collection.sharing;
res.commenting = collection.commenting;
res.templateManagement = collection.templateManagement;
res.permission = collection.permission;
res.deletedAt = collection.deletedAt;
res.archivedAt = collection.archivedAt;
res.deprecatedReason = collection.deprecatedReason;
res.archivedBy =
collection.archivedBy && presentUser(collection.archivedBy);
res.sourceMetadata = collection.sourceMetadata
? {
externalId: collection.sourceMetadata.externalId,
externalName: collection.sourceMetadata.externalName,
createdByName: collection.sourceMetadata.createdByName,
}
: undefined;
}
return res;
}