chore: Remove reliance on Markdown for document.getSummary, towards #3000
This commit is contained in:
@@ -5,9 +5,7 @@ import { can } from "@server/policies";
|
|||||||
import { getUserForJWT } from "@server/utils/jwt";
|
import { getUserForJWT } from "@server/utils/jwt";
|
||||||
import { AuthenticationError } from "../errors";
|
import { AuthenticationError } from "../errors";
|
||||||
|
|
||||||
@APM.trace({
|
@APM.trace()
|
||||||
spanName: "authentication",
|
|
||||||
})
|
|
||||||
export default class AuthenticationExtension implements Extension {
|
export default class AuthenticationExtension implements Extension {
|
||||||
async onAuthenticate({
|
async onAuthenticate({
|
||||||
connection,
|
connection,
|
||||||
|
|||||||
@@ -12,9 +12,7 @@ import Document from "@server/models/Document";
|
|||||||
import documentCollaborativeUpdater from "../commands/documentCollaborativeUpdater";
|
import documentCollaborativeUpdater from "../commands/documentCollaborativeUpdater";
|
||||||
import markdownToYDoc from "./utils/markdownToYDoc";
|
import markdownToYDoc from "./utils/markdownToYDoc";
|
||||||
|
|
||||||
@APM.trace({
|
@APM.trace()
|
||||||
spanName: "persistence",
|
|
||||||
})
|
|
||||||
export default class PersistenceExtension implements Extension {
|
export default class PersistenceExtension implements Extension {
|
||||||
/**
|
/**
|
||||||
* Map of documentId -> userIds that have modified the document since it
|
* Map of documentId -> userIds that have modified the document since it
|
||||||
|
|||||||
@@ -22,9 +22,7 @@ type SendMailOptions = {
|
|||||||
/**
|
/**
|
||||||
* Mailer class to send emails.
|
* Mailer class to send emails.
|
||||||
*/
|
*/
|
||||||
@APM.trace({
|
@APM.trace()
|
||||||
spanName: "mailer",
|
|
||||||
})
|
|
||||||
export class Mailer {
|
export class Mailer {
|
||||||
transporter: Transporter | undefined;
|
transporter: Transporter | undefined;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import removeMarkdown from "@tommoor/remove-markdown";
|
|
||||||
import { compact, uniq } from "lodash";
|
import { compact, uniq } from "lodash";
|
||||||
import randomstring from "randomstring";
|
import randomstring from "randomstring";
|
||||||
import type { SaveOptions } from "sequelize";
|
import type { SaveOptions } from "sequelize";
|
||||||
@@ -34,7 +33,6 @@ import MarkdownSerializer from "slate-md-serializer";
|
|||||||
import isUUID from "validator/lib/isUUID";
|
import isUUID from "validator/lib/isUUID";
|
||||||
import getTasks from "@shared/utils/getTasks";
|
import getTasks from "@shared/utils/getTasks";
|
||||||
import parseTitle from "@shared/utils/parseTitle";
|
import parseTitle from "@shared/utils/parseTitle";
|
||||||
import unescape from "@shared/utils/unescape";
|
|
||||||
import { SLUG_URL_REGEX } from "@shared/utils/urlHelpers";
|
import { SLUG_URL_REGEX } from "@shared/utils/urlHelpers";
|
||||||
import { DocumentValidation } from "@shared/validations";
|
import { DocumentValidation } from "@shared/validations";
|
||||||
import slugify from "@server/utils/slugify";
|
import slugify from "@server/utils/slugify";
|
||||||
@@ -48,6 +46,7 @@ import User from "./User";
|
|||||||
import View from "./View";
|
import View from "./View";
|
||||||
import ParanoidModel from "./base/ParanoidModel";
|
import ParanoidModel from "./base/ParanoidModel";
|
||||||
import Fix from "./decorators/Fix";
|
import Fix from "./decorators/Fix";
|
||||||
|
import DocumentHelper from "./helpers/DocumentHelper";
|
||||||
import Length from "./validators/Length";
|
import Length from "./validators/Length";
|
||||||
|
|
||||||
const serializer = new MarkdownSerializer();
|
const serializer = new MarkdownSerializer();
|
||||||
@@ -740,10 +739,8 @@ class Document extends ParanoidModel {
|
|||||||
};
|
};
|
||||||
|
|
||||||
getSummary = () => {
|
getSummary = () => {
|
||||||
const plain = removeMarkdown(unescape(this.text), {
|
const plainText = DocumentHelper.toPlainText(this);
|
||||||
stripHTML: false,
|
const lines = compact(plainText.split("\n"));
|
||||||
});
|
|
||||||
const lines = compact(plain.split("\n"));
|
|
||||||
const notEmpty = lines.length >= 1;
|
const notEmpty = lines.length >= 1;
|
||||||
|
|
||||||
if (this.version) {
|
if (this.version) {
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ import { isRTL } from "@shared/utils/rtl";
|
|||||||
import unescape from "@shared/utils/unescape";
|
import unescape from "@shared/utils/unescape";
|
||||||
import { parser, schema } from "@server/editor";
|
import { parser, schema } from "@server/editor";
|
||||||
import Logger from "@server/logging/Logger";
|
import Logger from "@server/logging/Logger";
|
||||||
import Document from "@server/models/Document";
|
import { APM } from "@server/logging/tracing";
|
||||||
|
import type Document from "@server/models/Document";
|
||||||
import type Revision from "@server/models/Revision";
|
import type Revision from "@server/models/Revision";
|
||||||
import User from "@server/models/User";
|
import User from "@server/models/User";
|
||||||
import diff from "@server/utils/diff";
|
import diff from "@server/utils/diff";
|
||||||
@@ -42,6 +43,7 @@ type HTMLOptions = {
|
|||||||
signedUrls?: boolean;
|
signedUrls?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@APM.trace()
|
||||||
export default class DocumentHelper {
|
export default class DocumentHelper {
|
||||||
/**
|
/**
|
||||||
* Returns the document as a Prosemirror Node. This method uses the
|
* Returns the document as a Prosemirror Node. This method uses the
|
||||||
@@ -176,7 +178,7 @@ export default class DocumentHelper {
|
|||||||
|
|
||||||
let output = dom.serialize();
|
let output = dom.serialize();
|
||||||
|
|
||||||
if (options?.signedUrls && document instanceof Document) {
|
if (options?.signedUrls && "teamId" in document) {
|
||||||
output = await DocumentHelper.attachmentsToSignedUrls(
|
output = await DocumentHelper.attachmentsToSignedUrls(
|
||||||
output,
|
output,
|
||||||
document.teamId
|
document.teamId
|
||||||
|
|||||||
Reference in New Issue
Block a user