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);
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
import { Notification } from "@server/models";
|
||||
import { APIContext } from "@server/types";
|
||||
import presentUser from "./user";
|
||||
import { presentComment, presentDocument } from ".";
|
||||
|
||||
export default async function presentNotification(notification: Notification) {
|
||||
export default async function presentNotification(
|
||||
ctx: APIContext | undefined,
|
||||
notification: Notification
|
||||
) {
|
||||
return {
|
||||
id: notification.id,
|
||||
viewedAt: notification.viewedAt,
|
||||
@@ -18,7 +22,7 @@ export default async function presentNotification(notification: Notification) {
|
||||
: undefined,
|
||||
documentId: notification.documentId,
|
||||
document: notification.document
|
||||
? await presentDocument(notification.document)
|
||||
? await presentDocument(ctx, notification.document)
|
||||
: undefined,
|
||||
revisionId: notification.revisionId,
|
||||
collectionId: notification.collectionId,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import parseTitle from "@shared/utils/parseTitle";
|
||||
import { traceFunction } from "@server/logging/tracing";
|
||||
import { Revision } from "@server/models";
|
||||
import DocumentHelper from "@server/models/helpers/DocumentHelper";
|
||||
import { DocumentHelper } from "@server/models/helpers/DocumentHelper";
|
||||
import presentUser from "./user";
|
||||
|
||||
async function presentRevision(revision: Revision, diff?: string) {
|
||||
@@ -12,7 +12,7 @@ async function presentRevision(revision: Revision, diff?: string) {
|
||||
id: revision.id,
|
||||
documentId: revision.documentId,
|
||||
title: strippedTitle,
|
||||
text: DocumentHelper.toMarkdown(revision),
|
||||
data: await DocumentHelper.toJSON(revision),
|
||||
emoji: revision.emoji ?? emoji,
|
||||
html: diff,
|
||||
createdAt: revision.createdAt,
|
||||
|
||||
Reference in New Issue
Block a user