JSON to client (#5553)
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { traceFunction } from "@server/logging/tracing";
|
||||
import { Document } from "@server/models";
|
||||
import TextHelper from "@server/models/helpers/TextHelper";
|
||||
import { DocumentHelper } from "@server/models/helpers/DocumentHelper";
|
||||
import { TextHelper } from "@server/models/helpers/TextHelper";
|
||||
import { APIContext } from "@server/types";
|
||||
import presentUser from "./user";
|
||||
|
||||
type Options = {
|
||||
@@ -8,6 +10,7 @@ type Options = {
|
||||
};
|
||||
|
||||
async function presentDocument(
|
||||
ctx: APIContext | undefined,
|
||||
document: Document,
|
||||
options: Options | null | undefined = {}
|
||||
) {
|
||||
@@ -15,17 +18,32 @@ async function presentDocument(
|
||||
isPublic: false,
|
||||
...options,
|
||||
};
|
||||
const text = options.isPublic
|
||||
? await TextHelper.attachmentsToSignedUrls(document.text, document.teamId)
|
||||
: document.text;
|
||||
|
||||
const asData = !ctx || Number(ctx?.headers["x-api-version"] ?? 0) >= 3;
|
||||
const text =
|
||||
options.isPublic && !asData
|
||||
? await TextHelper.attachmentsToSignedUrls(document.text, document.teamId)
|
||||
: document.text;
|
||||
|
||||
const data: Record<string, any> = {
|
||||
id: document.id,
|
||||
url: document.url,
|
||||
urlId: document.urlId,
|
||||
title: document.title,
|
||||
data: asData
|
||||
? await DocumentHelper.toJSON(
|
||||
document,
|
||||
options.isPublic
|
||||
? {
|
||||
signedUrls: 60,
|
||||
teamId: document.teamId,
|
||||
removeMarks: ["comment"],
|
||||
}
|
||||
: undefined
|
||||
)
|
||||
: undefined,
|
||||
text: asData ? undefined : text,
|
||||
emoji: document.emoji,
|
||||
text,
|
||||
tasks: document.tasks,
|
||||
createdAt: document.createdAt,
|
||||
createdBy: undefined,
|
||||
@@ -41,7 +59,7 @@ async function presentDocument(
|
||||
collectionId: undefined,
|
||||
parentDocumentId: undefined,
|
||||
lastViewedAt: undefined,
|
||||
isCollectionDeleted: await document.isCollectionDeleted(),
|
||||
isCollectionDeleted: undefined,
|
||||
};
|
||||
|
||||
if (!!document.views && document.views.length > 0) {
|
||||
@@ -51,6 +69,7 @@ async function presentDocument(
|
||||
if (!options.isPublic) {
|
||||
const source = await document.$get("import");
|
||||
|
||||
data.isCollectionDeleted = await document.isCollectionDeleted();
|
||||
data.collectionId = document.collectionId;
|
||||
data.parentDocumentId = document.parentDocumentId;
|
||||
data.createdBy = presentUser(document.createdBy);
|
||||
|
||||
Reference in New Issue
Block a user