mirror of
https://github.com/docmost/docmost.git
synced 2026-05-08 23:33:09 +08:00
Compare commits
9 Commits
editor-972
...
ratelimits
| Author | SHA1 | Date | |
|---|---|---|---|
| 61ae9703c9 | |||
| 3ba5cff98b | |||
| a062f7a165 | |||
| cbd0dd4a0b | |||
| 2d6d829581 | |||
| 5cea30cc5c | |||
| bca85a49d6 | |||
| c9cdfa0f17 | |||
| 412962204c |
@@ -733,7 +733,5 @@
|
||||
"Publish": "Publish.",
|
||||
"Security": "Security.",
|
||||
"Enforce SSO": "Enforce SSO.",
|
||||
"Once enforced, members will not be able to login with email and password.": "Once enforced, members will not be able to log in with email and password.",
|
||||
"Uploading {{name}}": "Uploading {{name}}",
|
||||
"Uploading file": "Uploading file"
|
||||
"Once enforced, members will not be able to login with email and password.": "Once enforced, members will not be able to log in with email and password."
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ function CommentMenu({
|
||||
{isResolved ? t("Re-open comment") : t("Resolve comment")}
|
||||
</Menu.Item>
|
||||
) : (
|
||||
<Tooltip label={upgradeLabel} position="left" withPortal={false}>
|
||||
<Tooltip label={upgradeLabel} position="left" withinPortal={false}>
|
||||
<Menu.Item disabled leftSection={<IconCircleCheck size={14} />}>
|
||||
{t("Resolve comment")}
|
||||
</Menu.Item>
|
||||
|
||||
@@ -10,7 +10,7 @@ import { useCallback } from "react";
|
||||
export default function AttachmentView(props: NodeViewProps) {
|
||||
const { t } = useTranslation();
|
||||
const { editor, node, getPos, selected } = props;
|
||||
const { url, name, size, mime, attachmentId } = node.attrs;
|
||||
const { url, name, size, mime, attachmentId, placeholder } = node.attrs;
|
||||
const { hovered, ref } = useHover();
|
||||
|
||||
const isPdf = mime === "application/pdf" || name?.toLowerCase().endsWith(".pdf");
|
||||
@@ -49,14 +49,14 @@ export default function AttachmentView(props: NodeViewProps) {
|
||||
h={25}
|
||||
>
|
||||
<Group wrap="nowrap" gap="sm" style={{ minWidth: 0, flex: 1 }}>
|
||||
{url ? (
|
||||
<IconPaperclip size={20} style={{ flexShrink: 0 }} />
|
||||
) : (
|
||||
{!url && placeholder ? (
|
||||
<Loader size={20} style={{ flexShrink: 0 }} />
|
||||
) : (
|
||||
<IconPaperclip size={20} style={{ flexShrink: 0 }} />
|
||||
)}
|
||||
|
||||
<Text component="span" size="md" truncate="end" style={{ minWidth: 0 }}>
|
||||
{url ? name : t("Uploading {{name}}", { name })}
|
||||
{!url && placeholder ? t("Uploading {{name}}", { name }) : name}
|
||||
</Text>
|
||||
|
||||
<Text component="span" size="sm" c="dimmed" style={{ flexShrink: 0 }}>
|
||||
|
||||
@@ -29,7 +29,7 @@ export default function AudioView(props: NodeViewProps) {
|
||||
|
||||
return (
|
||||
<NodeViewWrapper data-drag-handle>
|
||||
<div className={`${classes.audioWrapper} ${!safeSrc ? classes.skeleton : ''}`}>
|
||||
<div className={`${classes.audioWrapper} ${!safeSrc && placeholder ? classes.skeleton : ''}`}>
|
||||
{safeSrc && (
|
||||
<audio
|
||||
className={classes.audio}
|
||||
@@ -49,7 +49,7 @@ export default function AudioView(props: NodeViewProps) {
|
||||
<Loader size={20} pos="absolute" top={6} right={6} />
|
||||
</Group>
|
||||
)}
|
||||
{!safeSrc && !previewSrc && (
|
||||
{!safeSrc && !previewSrc && placeholder && (
|
||||
<Group justify="center" wrap="nowrap" gap="xs" maw="100%" px="md" h={54}>
|
||||
<Loader size={20} style={{ flexShrink: 0 }} />
|
||||
<Text component="span" size="sm" truncate="end">
|
||||
@@ -59,6 +59,9 @@ export default function AudioView(props: NodeViewProps) {
|
||||
</Text>
|
||||
</Group>
|
||||
)}
|
||||
{!safeSrc && !previewSrc && !placeholder && (
|
||||
<audio className={classes.audio} controls />
|
||||
)}
|
||||
</div>
|
||||
</NodeViewWrapper>
|
||||
);
|
||||
|
||||
@@ -33,7 +33,7 @@ export default function ImageView(props: NodeViewProps) {
|
||||
className={clsx(
|
||||
selected && "ProseMirror-selectednode",
|
||||
classes.imageWrapper,
|
||||
!src && classes.skeleton,
|
||||
!src && placeholder && classes.skeleton,
|
||||
alignClass,
|
||||
)}
|
||||
style={{
|
||||
@@ -55,7 +55,7 @@ export default function ImageView(props: NodeViewProps) {
|
||||
<Loader size={20} pos="absolute" bottom={6} right={6} />
|
||||
</Group>
|
||||
)}
|
||||
{!src && !previewSrc && (
|
||||
{!src && !previewSrc && placeholder && (
|
||||
<Group justify="center" wrap="nowrap" gap="xs" maw="100%" px="md">
|
||||
<Loader size={20} style={{ flexShrink: 0 }} />
|
||||
<Text component="span" size="sm" truncate="end">
|
||||
|
||||
@@ -73,15 +73,17 @@ export default function PdfView(props: NodeViewProps) {
|
||||
if (!src || !safeSrc) {
|
||||
return (
|
||||
<NodeViewWrapper data-drag-handle>
|
||||
<div className={`${classes.pdfWrapper} ${classes.skeleton}`} style={{ height: 600 }}>
|
||||
<Group justify="center" wrap="nowrap" gap="xs" maw="100%" px="md">
|
||||
<Loader size={20} style={{ flexShrink: 0 }} />
|
||||
<Text component="span" size="sm" truncate="end">
|
||||
{placeholder?.name
|
||||
? t("Uploading {{name}}", { name: placeholder.name })
|
||||
: t("Uploading file")}
|
||||
</Text>
|
||||
</Group>
|
||||
<div className={`${classes.pdfWrapper} ${placeholder ? classes.skeleton : ''}`} style={{ height: placeholder ? 600 : undefined }}>
|
||||
{placeholder && (
|
||||
<Group justify="center" wrap="nowrap" gap="xs" maw="100%" px="md">
|
||||
<Loader size={20} style={{ flexShrink: 0 }} />
|
||||
<Text component="span" size="sm" truncate="end">
|
||||
{placeholder?.name
|
||||
? t("Uploading {{name}}", { name: placeholder.name })
|
||||
: t("Uploading file")}
|
||||
</Text>
|
||||
</Group>
|
||||
)}
|
||||
</div>
|
||||
</NodeViewWrapper>
|
||||
);
|
||||
|
||||
@@ -33,7 +33,7 @@ export default function VideoView(props: NodeViewProps) {
|
||||
className={clsx(
|
||||
selected && "ProseMirror-selectednode",
|
||||
classes.videoWrapper,
|
||||
!src && classes.skeleton,
|
||||
!src && placeholder && classes.skeleton,
|
||||
alignClass,
|
||||
)}
|
||||
style={{
|
||||
@@ -60,7 +60,7 @@ export default function VideoView(props: NodeViewProps) {
|
||||
<Loader size={20} pos="absolute" top={6} right={6} />
|
||||
</Group>
|
||||
)}
|
||||
{!src && !previewSrc && (
|
||||
{!src && !previewSrc && placeholder && (
|
||||
<Group justify="center" wrap="nowrap" gap="xs" maw="100%" px="md">
|
||||
<Loader size={20} style={{ flexShrink: 0 }} />
|
||||
<Text component="span" size="sm" truncate="end">
|
||||
@@ -70,6 +70,9 @@ export default function VideoView(props: NodeViewProps) {
|
||||
</Text>
|
||||
</Group>
|
||||
)}
|
||||
{!src && !previewSrc && !placeholder && (
|
||||
<video className={classes.video} controls />
|
||||
)}
|
||||
</div>
|
||||
</NodeViewWrapper>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
// https://github.com/NiclasDev63/tiptap-extension-auto-joiner - MIT
|
||||
import { Extension } from "@tiptap/core";
|
||||
import { Plugin, PluginKey } from "@tiptap/pm/state";
|
||||
import { canJoin } from "@tiptap/pm/transform";
|
||||
import { getNodeType } from "@tiptap/react";
|
||||
import { NodeType } from "@tiptap/pm/model";
|
||||
import { Transaction } from "@tiptap/pm/state";
|
||||
|
||||
// https://discuss.prosemirror.net/t/how-to-autojoin-all-the-time/2957/4
|
||||
// Adapted from prosemirror-commands wrapDispatchForJoin
|
||||
function autoJoin(
|
||||
transactions: readonly Transaction[],
|
||||
newTr: Transaction,
|
||||
nodeTypes: NodeType[]
|
||||
) {
|
||||
// Collect changed ranges across all transactions, mapping earlier ranges
|
||||
// forward through later mappings so every position lands in newTr.doc space.
|
||||
let ranges: number[] = [];
|
||||
for (const tr of transactions) {
|
||||
for (let i = 0; i < tr.mapping.maps.length; i++) {
|
||||
let map = tr.mapping.maps[i];
|
||||
if (!map) continue;
|
||||
for (let j = 0; j < ranges.length; j++) ranges[j] = map.map(ranges[j]!);
|
||||
map.forEach((_s, _e, from, to) => ranges.push(from, to));
|
||||
}
|
||||
}
|
||||
|
||||
// Figure out which joinable points exist inside those ranges,
|
||||
// by checking all node boundaries in their parent nodes.
|
||||
// Resolve against newTr.doc — the same document we will join on.
|
||||
let joinable: number[] = [];
|
||||
for (let i = 0; i < ranges.length; i += 2) {
|
||||
let from = ranges[i]!,
|
||||
to = ranges[i + 1]!;
|
||||
let $from = newTr.doc.resolve(from),
|
||||
depth = $from.sharedDepth(to),
|
||||
parent = $from.node(depth);
|
||||
for (
|
||||
let index = $from.indexAfter(depth), pos = $from.after(depth + 1);
|
||||
pos <= to;
|
||||
++index
|
||||
) {
|
||||
let after = parent.maybeChild(index);
|
||||
if (!after) break;
|
||||
if (index && joinable.indexOf(pos) == -1) {
|
||||
let before = parent.child(index - 1);
|
||||
if (before.type == after.type && nodeTypes.includes(before.type))
|
||||
joinable.push(pos);
|
||||
}
|
||||
pos += after.nodeSize;
|
||||
}
|
||||
}
|
||||
|
||||
// Join the joinable points (reverse order to preserve earlier positions)
|
||||
let joined = false;
|
||||
joinable.sort((a, b) => a - b);
|
||||
for (let i = joinable.length - 1; i >= 0; i--) {
|
||||
if (canJoin(newTr.doc, joinable[i]!)) {
|
||||
newTr.join(joinable[i]!);
|
||||
joined = true;
|
||||
}
|
||||
}
|
||||
|
||||
return joined;
|
||||
}
|
||||
|
||||
export interface AutoJoinerOptions {
|
||||
elementsToJoin: string[];
|
||||
}
|
||||
|
||||
const AutoJoiner = Extension.create<AutoJoinerOptions>({
|
||||
name: "autoJoiner",
|
||||
|
||||
addOptions() {
|
||||
return {
|
||||
elementsToJoin: [],
|
||||
};
|
||||
},
|
||||
|
||||
addProseMirrorPlugins() {
|
||||
const plugin = new PluginKey(this.name);
|
||||
const joinableNodes = [
|
||||
this.editor.schema.nodes.bulletList,
|
||||
this.editor.schema.nodes.orderedList,
|
||||
];
|
||||
this.options.elementsToJoin.forEach((element) => {
|
||||
const nodeTyp = getNodeType(element, this.editor.schema);
|
||||
joinableNodes.push(nodeTyp);
|
||||
});
|
||||
|
||||
return [
|
||||
new Plugin({
|
||||
key: plugin,
|
||||
appendTransaction(transactions, _, newState) {
|
||||
let newTr = newState.tr;
|
||||
if (autoJoin(transactions, newTr, joinableNodes as NodeType[])) {
|
||||
return newTr;
|
||||
}
|
||||
},
|
||||
}),
|
||||
];
|
||||
},
|
||||
});
|
||||
|
||||
export default AutoJoiner;
|
||||
@@ -49,7 +49,7 @@ import {
|
||||
SharedStorage,
|
||||
Columns,
|
||||
Column,
|
||||
Status
|
||||
Status,
|
||||
} from "@docmost/editor-ext";
|
||||
import {
|
||||
randomElement,
|
||||
@@ -97,6 +97,7 @@ import i18n from "@/i18n.ts";
|
||||
import { MarkdownClipboard } from "@/features/editor/extensions/markdown-clipboard.ts";
|
||||
import EmojiCommand from "./emoji-command";
|
||||
import { countWords } from "alfaaz";
|
||||
import AutoJoiner from "@/features/editor/extensions/autojoiner.ts";
|
||||
|
||||
const lowlight = createLowlight(common);
|
||||
lowlight.register("mermaid", plaintext);
|
||||
@@ -252,8 +253,8 @@ export const mainExtensions = [
|
||||
resize: {
|
||||
enabled: true,
|
||||
directions: ["left", "right"],
|
||||
minWidth: 80,
|
||||
minHeight: 40,
|
||||
minWidth: 24,
|
||||
minHeight: 16,
|
||||
alwaysPreserveAspectRatio: true,
|
||||
//@ts-ignore
|
||||
createCustomHandle: createImageHandle,
|
||||
@@ -265,8 +266,8 @@ export const mainExtensions = [
|
||||
resize: {
|
||||
enabled: true,
|
||||
directions: ["left", "right"],
|
||||
minWidth: 80,
|
||||
minHeight: 40,
|
||||
minWidth: 24,
|
||||
minHeight: 16,
|
||||
alwaysPreserveAspectRatio: true,
|
||||
//@ts-ignore
|
||||
createCustomHandle: createResizeHandle,
|
||||
@@ -296,8 +297,8 @@ export const mainExtensions = [
|
||||
resize: {
|
||||
enabled: true,
|
||||
directions: ["left", "right"],
|
||||
minWidth: 80,
|
||||
minHeight: 40,
|
||||
minWidth: 24,
|
||||
minHeight: 16,
|
||||
alwaysPreserveAspectRatio: true,
|
||||
//@ts-ignore
|
||||
createCustomHandle: createResizeHandle,
|
||||
@@ -309,8 +310,8 @@ export const mainExtensions = [
|
||||
resize: {
|
||||
enabled: true,
|
||||
directions: ["left", "right"],
|
||||
minWidth: 80,
|
||||
minHeight: 40,
|
||||
minWidth: 24,
|
||||
minHeight: 16,
|
||||
alwaysPreserveAspectRatio: true,
|
||||
//@ts-ignore
|
||||
createCustomHandle: createResizeHandle,
|
||||
@@ -353,6 +354,9 @@ export const mainExtensions = [
|
||||
}).configure(),
|
||||
Columns,
|
||||
Column,
|
||||
AutoJoiner.configure({
|
||||
elementsToJoin: [],
|
||||
}),
|
||||
] as any;
|
||||
|
||||
type CollabExtensions = (provider: HocuspocusProvider, user: IUser) => any[];
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
// adapted from: https://github.com/aguingand/tiptap-markdown/blob/main/src/extensions/tiptap/clipboard.js - MIT
|
||||
import { Extension } from "@tiptap/core";
|
||||
import { Plugin, PluginKey } from "@tiptap/pm/state";
|
||||
import { DOMParser, Fragment, Slice } from "@tiptap/pm/model";
|
||||
import { Plugin, PluginKey, TextSelection } from "@tiptap/pm/state";
|
||||
import { DOMParser, DOMSerializer, Fragment, Slice } from "@tiptap/pm/model";
|
||||
import { find } from "linkifyjs";
|
||||
import { markdownToHtml } from "@docmost/editor-ext";
|
||||
import { markdownToHtml, htmlToMarkdown } from "@docmost/editor-ext";
|
||||
|
||||
export const MarkdownClipboard = Extension.create({
|
||||
name: "markdownClipboard",
|
||||
@@ -19,6 +19,27 @@ export const MarkdownClipboard = Extension.create({
|
||||
new Plugin({
|
||||
key: new PluginKey("markdownClipboard"),
|
||||
props: {
|
||||
clipboardTextSerializer: (slice) => {
|
||||
const listTypes = ["bulletList", "orderedList", "taskList"];
|
||||
let topLevelCount = 0;
|
||||
let hasList = false;
|
||||
slice.content.forEach((node) => {
|
||||
if (listTypes.includes(node.type.name)) {
|
||||
hasList = true;
|
||||
topLevelCount += node.childCount;
|
||||
} else {
|
||||
topLevelCount++;
|
||||
}
|
||||
});
|
||||
|
||||
if (!hasList || topLevelCount < 2) return null;
|
||||
|
||||
const div = document.createElement("div");
|
||||
const serializer = DOMSerializer.fromSchema(this.editor.schema);
|
||||
const fragment = serializer.serializeFragment(slice.content);
|
||||
div.appendChild(fragment);
|
||||
return htmlToMarkdown(div.innerHTML);
|
||||
},
|
||||
handlePaste: (view, event, slice) => {
|
||||
if (!event.clipboardData) {
|
||||
return false;
|
||||
@@ -29,26 +50,46 @@ export const MarkdownClipboard = Extension.create({
|
||||
}
|
||||
|
||||
const text = event.clipboardData.getData("text/plain");
|
||||
const html = event.clipboardData.getData("text/html");
|
||||
const vscode = event.clipboardData.getData("vscode-editor-data");
|
||||
const vscodeData = vscode ? JSON.parse(vscode) : undefined;
|
||||
const language = vscodeData?.mode;
|
||||
|
||||
if (language !== "markdown") {
|
||||
const isVscodeMarkdown = language === "markdown";
|
||||
const isPlainTextOnly = !html && !vscode && !!text;
|
||||
|
||||
if (!isVscodeMarkdown && !isPlainTextOnly) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isPlainTextOnly) {
|
||||
if ((view as any).input?.shiftKey || !this.options.transformPastedText) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const link = find(text, {
|
||||
defaultProtocol: "http",
|
||||
}).find((item) => item.isLink && item.value === text);
|
||||
|
||||
if (link) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const { tr } = view.state;
|
||||
const { from, to } = view.state.selection;
|
||||
|
||||
const html = markdownToHtml(text.replace(/\n+$/, ""));
|
||||
const parsed = markdownToHtml(text.replace(/\n+$/, ""));
|
||||
|
||||
const contentNodes = DOMParser.fromSchema(
|
||||
this.editor.schema,
|
||||
).parseSlice(elementFromString(html), {
|
||||
).parseSlice(elementFromString(parsed), {
|
||||
preserveWhitespace: true,
|
||||
});
|
||||
|
||||
tr.replaceRange(from, to, contentNodes);
|
||||
const insertEnd = tr.mapping.map(from, 1);
|
||||
tr.setSelection(TextSelection.near(tr.doc.resolve(Math.max(from, insertEnd - 2)), -1));
|
||||
tr.setMeta('paste', true)
|
||||
view.dispatch(tr);
|
||||
return true;
|
||||
@@ -84,26 +125,6 @@ export const MarkdownClipboard = Extension.create({
|
||||
|
||||
return slice;
|
||||
},
|
||||
clipboardTextParser: (text, context, plainText) => {
|
||||
const link = find(text, {
|
||||
defaultProtocol: "http",
|
||||
}).find((item) => item.isLink && item.value === text);
|
||||
|
||||
if (plainText || !this.options.transformPastedText || link) {
|
||||
// don't parse plaintext link to allow link paste handler to work
|
||||
// pasting with shift key prevents formatting
|
||||
return null;
|
||||
}
|
||||
|
||||
const parsed = markdownToHtml(text.replace(/\n+$/, ""));
|
||||
return DOMParser.fromSchema(this.editor.schema).parseSlice(
|
||||
elementFromString(parsed),
|
||||
{
|
||||
preserveWhitespace: true,
|
||||
context,
|
||||
},
|
||||
);
|
||||
},
|
||||
},
|
||||
}),
|
||||
];
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
"@langchain/core": "1.1.34",
|
||||
"@langchain/textsplitters": "1.0.1",
|
||||
"@modelcontextprotocol/sdk": "^1.27.1",
|
||||
"@nest-lab/throttler-storage-redis": "^1.2.0",
|
||||
"@nestjs-labs/nestjs-ioredis": "^11.0.4",
|
||||
"@nestjs/bullmq": "^11.0.4",
|
||||
"@nestjs/cache-manager": "^3.1.0",
|
||||
@@ -58,6 +59,7 @@
|
||||
"@nestjs/platform-socket.io": "^11.1.17",
|
||||
"@nestjs/schedule": "^6.1.1",
|
||||
"@nestjs/terminus": "^11.1.1",
|
||||
"@nestjs/throttler": "^6.5.0",
|
||||
"@nestjs/websockets": "^11.1.17",
|
||||
"@node-saml/passport-saml": "^5.1.0",
|
||||
"@react-email/components": "1.0.10",
|
||||
@@ -73,6 +75,7 @@
|
||||
"class-transformer": "^0.5.1",
|
||||
"class-validator": "^0.15.1",
|
||||
"cookie": "^1.1.1",
|
||||
"fastify-ip": "^2.0.0",
|
||||
"fs-extra": "^11.3.4",
|
||||
"happy-dom": "20.8.9",
|
||||
"ioredis": "^5.10.1",
|
||||
|
||||
@@ -26,6 +26,7 @@ import KeyvRedis from '@keyv/redis';
|
||||
import { LoggerModule } from './common/logger/logger.module';
|
||||
import { ClsModule } from 'nestjs-cls';
|
||||
import { NoopAuditModule } from './integrations/audit/audit.module';
|
||||
import { ThrottleModule } from './integrations/throttle/throttle.module';
|
||||
|
||||
const enterpriseModules = [];
|
||||
try {
|
||||
@@ -83,6 +84,7 @@ try {
|
||||
EventEmitterModule.forRoot(),
|
||||
SecurityModule,
|
||||
TelemetryModule,
|
||||
ThrottleModule,
|
||||
...enterpriseModules,
|
||||
],
|
||||
controllers: [AppController],
|
||||
|
||||
@@ -50,20 +50,12 @@ export function createPinoConfig(): Params {
|
||||
},
|
||||
},
|
||||
serializers: {
|
||||
req: (req) => {
|
||||
const forwardedFor = req.headers?.['x-forwarded-for'];
|
||||
const ip =
|
||||
req.headers?.['cf-connecting-ip'] ||
|
||||
(typeof forwardedFor === 'string' ? forwardedFor.split(',')[0]?.trim() : undefined) ||
|
||||
req.remoteAddress;
|
||||
|
||||
return {
|
||||
method: req.method,
|
||||
url: req.url,
|
||||
ip,
|
||||
userAgent: req.headers?.['user-agent'],
|
||||
};
|
||||
},
|
||||
req: (req) => ({
|
||||
method: req.method,
|
||||
url: req.url,
|
||||
ip: req.ip || req.remoteAddress,
|
||||
userAgent: req.headers?.['user-agent'],
|
||||
}),
|
||||
res: (res) => ({
|
||||
statusCode: res.statusCode,
|
||||
}),
|
||||
|
||||
@@ -18,7 +18,8 @@ export class AuditContextMiddleware implements NestMiddleware {
|
||||
|
||||
use(req: FastifyRequest['raw'], res: FastifyReply['raw'], next: () => void) {
|
||||
const workspaceId = (req as any).workspaceId ?? null;
|
||||
const ipAddress = this.extractIpAddress(req);
|
||||
|
||||
const ipAddress = (req as any).ip ?? (req as any).socket?.remoteAddress ?? null;
|
||||
|
||||
const userAgent =
|
||||
(req.headers['user-agent'] as string) ?? null;
|
||||
@@ -35,21 +36,4 @@ export class AuditContextMiddleware implements NestMiddleware {
|
||||
|
||||
next();
|
||||
}
|
||||
|
||||
private extractIpAddress(req: FastifyRequest['raw']): string | null {
|
||||
const xForwardedFor = req.headers['x-forwarded-for'];
|
||||
if (xForwardedFor) {
|
||||
const ips = Array.isArray(xForwardedFor)
|
||||
? xForwardedFor[0]
|
||||
: xForwardedFor.split(',')[0];
|
||||
return ips?.trim() ?? null;
|
||||
}
|
||||
|
||||
const xRealIp = req.headers['x-real-ip'];
|
||||
if (xRealIp) {
|
||||
return Array.isArray(xRealIp) ? xRealIp[0] : xRealIp;
|
||||
}
|
||||
|
||||
return (req as any).socket?.remoteAddress ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
UseGuards,
|
||||
Logger,
|
||||
} from '@nestjs/common';
|
||||
import { SkipThrottle, ThrottlerGuard } from '@nestjs/throttler';
|
||||
import { LoginDto } from './dto/login.dto';
|
||||
import { AuthService } from './services/auth.service';
|
||||
import { SessionService } from '../session/session.service';
|
||||
@@ -33,6 +34,7 @@ import {
|
||||
IAuditService,
|
||||
} from '../../integrations/audit/audit.service';
|
||||
|
||||
@UseGuards(ThrottlerGuard)
|
||||
@Controller('auth')
|
||||
export class AuthController {
|
||||
private readonly logger = new Logger(AuthController.name);
|
||||
@@ -111,6 +113,7 @@ export class AuthController {
|
||||
return workspace;
|
||||
}
|
||||
|
||||
@SkipThrottle()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@Post('change-password')
|
||||
@@ -173,6 +176,7 @@ export class AuthController {
|
||||
return this.authService.verifyUserToken(verifyUserTokenDto, workspace.id);
|
||||
}
|
||||
|
||||
@SkipThrottle()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@Post('collab-token')
|
||||
@@ -183,6 +187,7 @@ export class AuthController {
|
||||
return this.authService.getCollabToken(user, workspace.id);
|
||||
}
|
||||
|
||||
@SkipThrottle()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@Post('logout')
|
||||
|
||||
@@ -0,0 +1,333 @@
|
||||
import { type Kysely, sql } from 'kysely';
|
||||
|
||||
export async function up(db: Kysely<any>): Promise<void> {
|
||||
await db.schema
|
||||
.createIndex('idx_group_users_user_id')
|
||||
.ifNotExists()
|
||||
.on('group_users')
|
||||
.column('user_id')
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.createIndex('idx_space_members_user_id')
|
||||
.ifNotExists()
|
||||
.on('space_members')
|
||||
.column('user_id')
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.createIndex('idx_space_members_group_id')
|
||||
.ifNotExists()
|
||||
.on('space_members')
|
||||
.column('group_id')
|
||||
.execute();
|
||||
|
||||
// Page tree
|
||||
await sql`
|
||||
CREATE INDEX IF NOT EXISTS idx_pages_space_parent_position
|
||||
ON pages (space_id, parent_page_id, position COLLATE "C")
|
||||
WHERE deleted_at IS NULL
|
||||
`.execute(db);
|
||||
|
||||
await sql`
|
||||
CREATE INDEX IF NOT EXISTS idx_pages_parent_page_id
|
||||
ON pages (parent_page_id)
|
||||
WHERE deleted_at IS NULL
|
||||
`.execute(db);
|
||||
|
||||
// Recent pages query
|
||||
await sql`
|
||||
CREATE INDEX IF NOT EXISTS idx_pages_space_updated
|
||||
ON pages (space_id, updated_at DESC)
|
||||
WHERE deleted_at IS NULL
|
||||
`.execute(db);
|
||||
|
||||
// Trash view
|
||||
await sql`
|
||||
CREATE INDEX IF NOT EXISTS idx_pages_space_deleted
|
||||
ON pages (space_id, deleted_at DESC)
|
||||
WHERE deleted_at IS NOT NULL
|
||||
`.execute(db);
|
||||
|
||||
await sql`
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_workspaces_hostname_lower
|
||||
ON workspaces (LOWER(hostname))
|
||||
`.execute(db);
|
||||
|
||||
await db.schema
|
||||
.createIndex('idx_workspaces_created_at')
|
||||
.ifNotExists()
|
||||
.on('workspaces')
|
||||
.column('created_at')
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.createIndex('idx_users_workspace_deleted')
|
||||
.ifNotExists()
|
||||
.on('users')
|
||||
.columns(['workspace_id', 'deleted_at'])
|
||||
.execute();
|
||||
|
||||
await sql`
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_spaces_slug_lower_workspace
|
||||
ON spaces (LOWER(slug), workspace_id)
|
||||
`.execute(db);
|
||||
|
||||
await db.schema
|
||||
.createIndex('idx_spaces_workspace_id')
|
||||
.ifNotExists()
|
||||
.on('spaces')
|
||||
.column('workspace_id')
|
||||
.execute();
|
||||
|
||||
await sql`
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_groups_name_lower_workspace
|
||||
ON groups (LOWER(name), workspace_id)
|
||||
`.execute(db);
|
||||
|
||||
await db.schema
|
||||
.createIndex('idx_groups_workspace_id')
|
||||
.ifNotExists()
|
||||
.on('groups')
|
||||
.column('workspace_id')
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.createIndex('idx_shares_page_id')
|
||||
.ifNotExists()
|
||||
.on('shares')
|
||||
.column('page_id')
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.createIndex('idx_attachments_page_id')
|
||||
.ifNotExists()
|
||||
.on('attachments')
|
||||
.column('page_id')
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.createIndex('idx_attachments_space_id')
|
||||
.ifNotExists()
|
||||
.on('attachments')
|
||||
.column('space_id')
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.createIndex('idx_comments_page_id')
|
||||
.ifNotExists()
|
||||
.on('comments')
|
||||
.column('page_id')
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.createIndex('idx_comments_parent_comment_id')
|
||||
.ifNotExists()
|
||||
.on('comments')
|
||||
.column('parent_comment_id')
|
||||
.execute();
|
||||
|
||||
await sql`
|
||||
CREATE INDEX IF NOT EXISTS idx_page_history_page_created
|
||||
ON page_history (page_id, created_at DESC)
|
||||
`.execute(db);
|
||||
|
||||
await db.schema
|
||||
.createIndex('idx_attachments_workspace_id')
|
||||
.ifNotExists()
|
||||
.on('attachments')
|
||||
.column('workspace_id')
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.createIndex('idx_backlinks_target_page_id')
|
||||
.ifNotExists()
|
||||
.on('backlinks')
|
||||
.column('target_page_id')
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.createIndex('idx_pages_workspace_id')
|
||||
.ifNotExists()
|
||||
.on('pages')
|
||||
.column('workspace_id')
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.createIndex('idx_pages_creator_id')
|
||||
.ifNotExists()
|
||||
.on('pages')
|
||||
.column('creator_id')
|
||||
.execute();
|
||||
|
||||
// Notifications: FK cascade from pages, spaces, comments
|
||||
await db.schema
|
||||
.createIndex('idx_notifications_page_id')
|
||||
.ifNotExists()
|
||||
.on('notifications')
|
||||
.column('page_id')
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.createIndex('idx_notifications_space_id')
|
||||
.ifNotExists()
|
||||
.on('notifications')
|
||||
.column('space_id')
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.createIndex('idx_notifications_comment_id')
|
||||
.ifNotExists()
|
||||
.on('notifications')
|
||||
.column('comment_id')
|
||||
.execute();
|
||||
|
||||
// Watchers: cleanup queries and FK cascade
|
||||
await db.schema
|
||||
.createIndex('idx_watchers_user_workspace')
|
||||
.ifNotExists()
|
||||
.on('watchers')
|
||||
.columns(['user_id', 'workspace_id'])
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.createIndex('idx_watchers_space_id')
|
||||
.ifNotExists()
|
||||
.on('watchers')
|
||||
.column('space_id')
|
||||
.execute();
|
||||
|
||||
// Auth providers: all queries filter by workspaceId
|
||||
await db.schema
|
||||
.createIndex('idx_auth_providers_workspace_id')
|
||||
.ifNotExists()
|
||||
.on('auth_providers')
|
||||
.column('workspace_id')
|
||||
.execute();
|
||||
|
||||
// Auth accounts: SSO login lookup by provider user
|
||||
await db.schema
|
||||
.createIndex('idx_auth_accounts_provider_user_id')
|
||||
.ifNotExists()
|
||||
.on('auth_accounts')
|
||||
.columns(['provider_user_id', 'auth_provider_id'])
|
||||
.execute();
|
||||
|
||||
// Workspace invitations: listing and SSO lookup
|
||||
await db.schema
|
||||
.createIndex('idx_workspace_invitations_workspace_id')
|
||||
.ifNotExists()
|
||||
.on('workspace_invitations')
|
||||
.column('workspace_id')
|
||||
.execute();
|
||||
|
||||
// API keys: query and FK cascade
|
||||
await db.schema
|
||||
.createIndex('idx_api_keys_workspace_id')
|
||||
.ifNotExists()
|
||||
.on('api_keys')
|
||||
.column('workspace_id')
|
||||
.execute();
|
||||
|
||||
// User sessions: delete queries and FK cascade on all session states
|
||||
await db.schema
|
||||
.createIndex('idx_user_sessions_user_workspace')
|
||||
.ifNotExists()
|
||||
.on('user_sessions')
|
||||
.columns(['user_id', 'workspace_id'])
|
||||
.execute();
|
||||
}
|
||||
|
||||
export async function down(db: Kysely<any>): Promise<void> {
|
||||
await db.schema.dropIndex('idx_group_users_user_id').ifExists().execute();
|
||||
await db.schema.dropIndex('idx_space_members_user_id').ifExists().execute();
|
||||
await db.schema.dropIndex('idx_space_members_group_id').ifExists().execute();
|
||||
await db.schema
|
||||
.dropIndex('idx_pages_space_parent_position')
|
||||
.ifExists()
|
||||
.execute();
|
||||
await db.schema.dropIndex('idx_pages_parent_page_id').ifExists().execute();
|
||||
await db.schema.dropIndex('idx_pages_space_updated').ifExists().execute();
|
||||
await db.schema.dropIndex('idx_pages_space_deleted').ifExists().execute();
|
||||
await db.schema
|
||||
.dropIndex('idx_workspaces_hostname_lower')
|
||||
.ifExists()
|
||||
.execute();
|
||||
await db.schema.dropIndex('idx_workspaces_created_at').ifExists().execute();
|
||||
await db.schema
|
||||
.dropIndex('idx_users_workspace_deleted')
|
||||
.ifExists()
|
||||
.execute();
|
||||
await db.schema
|
||||
.dropIndex('idx_spaces_slug_lower_workspace')
|
||||
.ifExists()
|
||||
.execute();
|
||||
await db.schema
|
||||
.dropIndex('idx_spaces_workspace_id')
|
||||
.ifExists()
|
||||
.execute();
|
||||
await db.schema
|
||||
.dropIndex('idx_groups_name_lower_workspace')
|
||||
.ifExists()
|
||||
.execute();
|
||||
await db.schema.dropIndex('idx_groups_workspace_id').ifExists().execute();
|
||||
await db.schema.dropIndex('idx_shares_page_id').ifExists().execute();
|
||||
await db.schema.dropIndex('idx_attachments_page_id').ifExists().execute();
|
||||
await db.schema.dropIndex('idx_attachments_space_id').ifExists().execute();
|
||||
await db.schema.dropIndex('idx_comments_page_id').ifExists().execute();
|
||||
await db.schema
|
||||
.dropIndex('idx_comments_parent_comment_id')
|
||||
.ifExists()
|
||||
.execute();
|
||||
await db.schema
|
||||
.dropIndex('idx_page_history_page_created')
|
||||
.ifExists()
|
||||
.execute();
|
||||
await db.schema
|
||||
.dropIndex('idx_attachments_workspace_id')
|
||||
.ifExists()
|
||||
.execute();
|
||||
await db.schema
|
||||
.dropIndex('idx_backlinks_target_page_id')
|
||||
.ifExists()
|
||||
.execute();
|
||||
await db.schema.dropIndex('idx_pages_workspace_id').ifExists().execute();
|
||||
await db.schema.dropIndex('idx_pages_creator_id').ifExists().execute();
|
||||
await db.schema
|
||||
.dropIndex('idx_notifications_page_id')
|
||||
.ifExists()
|
||||
.execute();
|
||||
await db.schema
|
||||
.dropIndex('idx_notifications_space_id')
|
||||
.ifExists()
|
||||
.execute();
|
||||
await db.schema
|
||||
.dropIndex('idx_notifications_comment_id')
|
||||
.ifExists()
|
||||
.execute();
|
||||
await db.schema
|
||||
.dropIndex('idx_watchers_user_workspace')
|
||||
.ifExists()
|
||||
.execute();
|
||||
await db.schema.dropIndex('idx_watchers_space_id').ifExists().execute();
|
||||
await db.schema
|
||||
.dropIndex('idx_auth_providers_workspace_id')
|
||||
.ifExists()
|
||||
.execute();
|
||||
await db.schema
|
||||
.dropIndex('idx_auth_accounts_provider_user_id')
|
||||
.ifExists()
|
||||
.execute();
|
||||
await db.schema
|
||||
.dropIndex('idx_workspace_invitations_workspace_id')
|
||||
.ifExists()
|
||||
.execute();
|
||||
await db.schema
|
||||
.dropIndex('idx_api_keys_workspace_id')
|
||||
.ifExists()
|
||||
.execute();
|
||||
await db.schema
|
||||
.dropIndex('idx_user_sessions_user_workspace')
|
||||
.ifExists()
|
||||
.execute();
|
||||
}
|
||||
+1
-1
Submodule apps/server/src/ee updated: f486726088...350ef574e3
@@ -61,7 +61,7 @@ export class ExportController {
|
||||
|
||||
await this.pageAccessService.validateCanView(page, user);
|
||||
|
||||
const zipFileStream = await this.exportService.exportPages(
|
||||
const result = await this.exportService.exportPages(
|
||||
dto.pageId,
|
||||
dto.format,
|
||||
dto.includeAttachments,
|
||||
@@ -83,15 +83,29 @@ export class ExportController {
|
||||
},
|
||||
});
|
||||
|
||||
const fileName = sanitize(page.title || 'untitled') + '.zip';
|
||||
if (result.type === 'file') {
|
||||
const ext = getExportExtension(dto.format);
|
||||
const fileName = sanitize(page.title || 'untitled') + ext;
|
||||
const contentType = getMimeType(path.extname(fileName));
|
||||
|
||||
res.headers({
|
||||
'Content-Type': 'application/zip',
|
||||
'Content-Disposition':
|
||||
'attachment; filename="' + encodeURIComponent(fileName) + '"',
|
||||
});
|
||||
res.headers({
|
||||
'Content-Type': contentType,
|
||||
'Content-Disposition':
|
||||
'attachment; filename="' + encodeURIComponent(fileName) + '"',
|
||||
});
|
||||
|
||||
res.send(zipFileStream);
|
||||
res.send(result.content);
|
||||
} else {
|
||||
const fileName = sanitize(page.title || 'untitled') + '.zip';
|
||||
|
||||
res.headers({
|
||||
'Content-Type': 'application/zip',
|
||||
'Content-Disposition':
|
||||
'attachment; filename="' + encodeURIComponent(fileName) + '"',
|
||||
});
|
||||
|
||||
res.send(result.stream);
|
||||
}
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
|
||||
@@ -150,6 +150,13 @@ export class ExportService {
|
||||
// set to null to make export of pages with parentId work
|
||||
pages[parentPageIndex].parentPageId = null;
|
||||
|
||||
const isSinglePage = pages.length === 1 && !includeAttachments;
|
||||
|
||||
if (isSinglePage) {
|
||||
const pageContent = await this.exportPage(format, pages[0], true);
|
||||
return { type: 'file' as const, content: pageContent, page: pages[0] };
|
||||
}
|
||||
|
||||
const tree = buildTree(pages as Page[]);
|
||||
|
||||
const baseUrl = await this.getWorkspaceBaseUrl(pages[0].workspaceId);
|
||||
@@ -170,7 +177,7 @@ export class ExportService {
|
||||
compression: 'DEFLATE',
|
||||
});
|
||||
|
||||
return zipFile;
|
||||
return { type: 'zip' as const, stream: zipFile, page: pages[0] };
|
||||
}
|
||||
|
||||
async exportSpace(
|
||||
|
||||
@@ -193,6 +193,8 @@ export class ImportAttachmentService {
|
||||
// Build a map from resolved archive path → real filename from Confluence
|
||||
// metadata. Confluence Server archives often store files under numeric IDs
|
||||
// (e.g. "attachments/65601/65602") instead of the original filename.
|
||||
// Also register aliases so HTML references using the original filename
|
||||
// (e.g. "attachments/pageId/original.mp3") resolve to the numeric path.
|
||||
const pageDir = path.dirname(pageRelativePath);
|
||||
const attachmentNameByRelPath = new Map<string, string>();
|
||||
for (const attachment of pageAttachments) {
|
||||
@@ -203,6 +205,13 @@ export class ImportAttachmentService {
|
||||
);
|
||||
if (relPath && attachment.fileName) {
|
||||
attachmentNameByRelPath.set(relPath, attachment.fileName);
|
||||
|
||||
const dir = path.posix.dirname(relPath);
|
||||
const aliasKey = `${dir}/${attachment.fileName}`;
|
||||
if (!attachmentCandidates.has(aliasKey)) {
|
||||
attachmentCandidates.set(aliasKey, attachmentCandidates.get(relPath)!);
|
||||
attachmentNameByRelPath.set(aliasKey, attachment.fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -562,18 +571,31 @@ export class ImportAttachmentService {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if already processed (was referenced in HTML)
|
||||
if (processed.has(href)) {
|
||||
continue;
|
||||
}
|
||||
// Resolve the metadata href to the actual archive path
|
||||
const resolvedHref = resolveRelativeAttachmentPath(
|
||||
href,
|
||||
pageDir,
|
||||
attachmentCandidates,
|
||||
);
|
||||
if (!resolvedHref) continue;
|
||||
|
||||
// Skip if the file doesn't exist
|
||||
if (!attachmentCandidates.has(href)) {
|
||||
// Check if already processed (was referenced in HTML).
|
||||
// Inline elements may have been processed under an alias key (original
|
||||
// filename) rather than the numeric archive path, so also check whether
|
||||
// the underlying absolute file path has already been uploaded.
|
||||
const absPath = attachmentCandidates.get(resolvedHref);
|
||||
const alreadyProcessed =
|
||||
processed.has(resolvedHref) ||
|
||||
(absPath &&
|
||||
Array.from(processed.values()).some(
|
||||
(entry) => entry.abs === absPath,
|
||||
));
|
||||
if (alreadyProcessed) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// This attachment was in the list but not referenced in HTML - add it
|
||||
const { attachmentId, apiFilePath, abs } = processFile(href);
|
||||
const { attachmentId, apiFilePath, abs } = processFile(resolvedHref);
|
||||
const mime = mimeType || getMimeType(abs);
|
||||
|
||||
// Add as attachment node at the end
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ThrottlerModule } from '@nestjs/throttler';
|
||||
import { ThrottlerStorageRedisService } from '@nest-lab/throttler-storage-redis';
|
||||
import { EnvironmentService } from '../environment/environment.service';
|
||||
import { EnvironmentModule } from '../environment/environment.module';
|
||||
import { parseRedisUrl } from '../../common/helpers';
|
||||
import Redis from 'ioredis';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
ThrottlerModule.forRootAsync({
|
||||
imports: [EnvironmentModule],
|
||||
useFactory: (environmentService: EnvironmentService) => {
|
||||
const redisConfig = parseRedisUrl(environmentService.getRedisUrl());
|
||||
|
||||
return {
|
||||
throttlers: [{ name: 'auth', ttl: 60_000, limit: 10 }],
|
||||
errorMessage: 'Too many requests',
|
||||
storage: new ThrottlerStorageRedisService(
|
||||
new Redis({
|
||||
host: redisConfig.host,
|
||||
port: redisConfig.port,
|
||||
password: redisConfig.password,
|
||||
db: redisConfig.db,
|
||||
family: redisConfig.family,
|
||||
keyPrefix: 'throttle:',
|
||||
}),
|
||||
),
|
||||
};
|
||||
},
|
||||
inject: [EnvironmentService],
|
||||
}),
|
||||
],
|
||||
})
|
||||
export class ThrottleModule {}
|
||||
@@ -10,6 +10,7 @@ import { TransformHttpResponseInterceptor } from './common/interceptors/http-res
|
||||
import { WsRedisIoAdapter } from './ws/adapter/ws-redis.adapter';
|
||||
import fastifyMultipart from '@fastify/multipart';
|
||||
import fastifyCookie from '@fastify/cookie';
|
||||
import fastifyIp from 'fastify-ip';
|
||||
import { InternalLogFilter } from './common/logger/internal-log-filter';
|
||||
|
||||
async function bootstrap() {
|
||||
@@ -45,6 +46,7 @@ async function bootstrap() {
|
||||
|
||||
app.useWebSocketAdapter(redisIoAdapter);
|
||||
|
||||
await app.register(fastifyIp);
|
||||
await app.register(fastifyMultipart);
|
||||
await app.register(fastifyCookie);
|
||||
|
||||
|
||||
@@ -9,5 +9,7 @@
|
||||
"main": "dist/index.js",
|
||||
"module": "./src/index.ts",
|
||||
"types": "dist/index.d.ts",
|
||||
"dependencies": {}
|
||||
"dependencies": {
|
||||
"marked": "17.0.5"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,18 +5,23 @@ import { mathInlineExtension } from "./math-inline.marked";
|
||||
|
||||
marked.use({
|
||||
renderer: {
|
||||
// @ts-ignore
|
||||
list(body: string, isOrdered: boolean, start: number) {
|
||||
if (isOrdered) {
|
||||
const startAttr = start !== 1 ? ` start="${start}"` : "";
|
||||
return `<ol ${startAttr}>\n${body}</ol>\n`;
|
||||
list({ ordered, start, items }) {
|
||||
let body = "";
|
||||
for (const item of items) {
|
||||
body += this.listitem(item);
|
||||
}
|
||||
|
||||
const dataType = body.includes(`<input`) ? ' data-type="taskList"' : "";
|
||||
if (ordered) {
|
||||
const startAttr = start !== 1 ? ` start="${start}"` : "";
|
||||
return `<ol${startAttr}>\n${body}</ol>\n`;
|
||||
}
|
||||
|
||||
const isTaskList = items.some((item) => item.task);
|
||||
const dataType = isTaskList ? ' data-type="taskList"' : "";
|
||||
return `<ul${dataType}>\n${body}</ul>\n`;
|
||||
},
|
||||
// @ts-ignore
|
||||
listitem({ text, raw, task: isTask, checked: isChecked }): string {
|
||||
listitem({ tokens, task: isTask, checked: isChecked }) {
|
||||
const text = this.parser.parse(tokens);
|
||||
if (!isTask) {
|
||||
return `<li>${text}</li>\n`;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ export function htmlToMarkdown(html: string): string {
|
||||
callout,
|
||||
preserveDetail,
|
||||
listParagraph,
|
||||
orderedListItem,
|
||||
mathInline,
|
||||
mathBlock,
|
||||
iframeEmbed,
|
||||
@@ -41,6 +42,40 @@ function listParagraph(turndownService: _TurndownService) {
|
||||
});
|
||||
}
|
||||
|
||||
function orderedListItem(turndownService: _TurndownService) {
|
||||
turndownService.addRule('orderedListItem', {
|
||||
filter: function (node: HTMLInputElement) {
|
||||
return node.nodeName === 'LI' && node.getAttribute('data-type') !== 'taskItem';
|
||||
},
|
||||
replacement: (content: string, node: HTMLInputElement, options: any) => {
|
||||
const parent = node.parentNode as HTMLElement;
|
||||
if (parent.nodeName !== 'OL' && parent.nodeName !== 'UL') {
|
||||
return content;
|
||||
}
|
||||
|
||||
content = content
|
||||
.replace(/^\n+/, '')
|
||||
.replace(/\n+$/, '\n')
|
||||
.replace(/\n/gm, '\n ');
|
||||
|
||||
let prefix: string;
|
||||
if (parent.nodeName === 'OL') {
|
||||
const start = parseInt(parent.getAttribute('start') || '1', 10);
|
||||
const index = Array.prototype.indexOf.call(parent.children, node);
|
||||
prefix = `${start + index}. `;
|
||||
} else {
|
||||
prefix = `${options.bulletListMarker} `;
|
||||
}
|
||||
|
||||
return (
|
||||
prefix +
|
||||
content +
|
||||
(node.nextSibling && !/\n$/.test(content) ? '\n' : '')
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function callout(turndownService: _TurndownService) {
|
||||
turndownService.addRule('callout', {
|
||||
filter: function (node: HTMLInputElement) {
|
||||
@@ -63,25 +98,17 @@ function taskList(turndownService: _TurndownService) {
|
||||
node.parentNode.nodeName === 'UL'
|
||||
);
|
||||
},
|
||||
replacement: function (content: string, node: HTMLInputElement) {
|
||||
const checkbox = node.querySelector(
|
||||
'input[type="checkbox"]',
|
||||
) as HTMLInputElement;
|
||||
const isChecked = checkbox.checked;
|
||||
replacement: function (_content: string, node: HTMLInputElement) {
|
||||
const isChecked = node.getAttribute('data-checked') === 'true';
|
||||
const div = node.querySelector('div');
|
||||
const text = div ? div.textContent.trim() : node.textContent.trim();
|
||||
|
||||
// Process content like regular list items
|
||||
content = content
|
||||
.replace(/^\n+/, '') // remove leading newlines
|
||||
.replace(/\n+$/, '\n') // replace trailing newlines with just a single one
|
||||
.replace(/\n/gm, '\n '); // indent nested content with 2 spaces
|
||||
|
||||
// Create the checkbox prefix
|
||||
const prefix = `- ${isChecked ? '[x]' : '[ ]'} `;
|
||||
|
||||
return (
|
||||
prefix +
|
||||
content +
|
||||
(node.nextSibling && !/\n$/.test(content) ? '\n' : '')
|
||||
text +
|
||||
(node.nextSibling && !/\n$/.test(text) ? '\n' : '')
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
Generated
+53
-1
@@ -493,6 +493,9 @@ importers:
|
||||
'@modelcontextprotocol/sdk':
|
||||
specifier: ^1.27.1
|
||||
version: 1.27.1(@cfworker/json-schema@4.1.1)(zod@4.3.6)
|
||||
'@nest-lab/throttler-storage-redis':
|
||||
specifier: ^1.2.0
|
||||
version: 1.2.0(@nestjs/common@11.1.17(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.17)(@nestjs/throttler@6.5.0(@nestjs/common@11.1.17(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.17)(reflect-metadata@0.2.2))(ioredis@5.10.1)(reflect-metadata@0.2.2)
|
||||
'@nestjs-labs/nestjs-ioredis':
|
||||
specifier: ^11.0.4
|
||||
version: 11.0.4(@nestjs/common@11.1.17(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.17)(ioredis@5.10.1)
|
||||
@@ -535,6 +538,9 @@ importers:
|
||||
'@nestjs/terminus':
|
||||
specifier: ^11.1.1
|
||||
version: 11.1.1(@nestjs/common@11.1.17(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.17)(reflect-metadata@0.2.2)(rxjs@7.8.2)
|
||||
'@nestjs/throttler':
|
||||
specifier: ^6.5.0
|
||||
version: 6.5.0(@nestjs/common@11.1.17(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.17)(reflect-metadata@0.2.2)
|
||||
'@nestjs/websockets':
|
||||
specifier: ^11.1.17
|
||||
version: 11.1.17(@nestjs/common@11.1.17(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.17)(@nestjs/platform-socket.io@11.1.17)(reflect-metadata@0.2.2)(rxjs@7.8.2)
|
||||
@@ -580,6 +586,9 @@ importers:
|
||||
cookie:
|
||||
specifier: ^1.1.1
|
||||
version: 1.1.1
|
||||
fastify-ip:
|
||||
specifier: ^2.0.0
|
||||
version: 2.0.0
|
||||
fs-extra:
|
||||
specifier: ^11.3.4
|
||||
version: 11.3.4
|
||||
@@ -801,7 +810,11 @@ importers:
|
||||
specifier: ^8.57.1
|
||||
version: 8.57.1(eslint@9.39.4(jiti@2.4.2))(typescript@5.9.3)
|
||||
|
||||
packages/editor-ext: {}
|
||||
packages/editor-ext:
|
||||
dependencies:
|
||||
marked:
|
||||
specifier: 17.0.5
|
||||
version: 17.0.5
|
||||
|
||||
packages:
|
||||
|
||||
@@ -2921,6 +2934,15 @@ packages:
|
||||
'@napi-rs/wasm-runtime@1.1.1':
|
||||
resolution: {integrity: sha512-p64ah1M1ld8xjWv3qbvFwHiFVWrq1yFvV4f7w+mzaqiR4IlSgkqhcRdHwsGgomwzBH51sRY4NEowLxnaBjcW/A==}
|
||||
|
||||
'@nest-lab/throttler-storage-redis@1.2.0':
|
||||
resolution: {integrity: sha512-tMkUyo68NCKTR+zILk+EC35SMYBtDPZY2mCj7ZaCietWGVTnuP4zwq9ERYfvU6kJv6h8teNZrC6MJCmY6/dljw==}
|
||||
peerDependencies:
|
||||
'@nestjs/common': ^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0
|
||||
'@nestjs/core': ^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0
|
||||
'@nestjs/throttler': '>=6.0.0'
|
||||
ioredis: '>=5.0.0'
|
||||
reflect-metadata: ^0.2.1
|
||||
|
||||
'@nestjs-labs/nestjs-ioredis@11.0.4':
|
||||
resolution: {integrity: sha512-4jPNOrxDiwNMIN5OLmsMWhA782kxv/ZBxkySX9l8n6sr55acHX/BciaFsOXVa/ILsm+Y7893y98/6WNhmEoiNQ==}
|
||||
engines: {node: '>=16'}
|
||||
@@ -3123,6 +3145,13 @@ packages:
|
||||
'@nestjs/platform-express':
|
||||
optional: true
|
||||
|
||||
'@nestjs/throttler@6.5.0':
|
||||
resolution: {integrity: sha512-9j0ZRfH0QE1qyrj9JjIRDz5gQLPqq9yVC2nHsrosDVAfI5HHw08/aUAWx9DZLSdQf4HDkmhTTEGLrRFHENvchQ==}
|
||||
peerDependencies:
|
||||
'@nestjs/common': ^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0
|
||||
'@nestjs/core': ^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0
|
||||
reflect-metadata: ^0.1.13 || ^0.2.0
|
||||
|
||||
'@nestjs/websockets@11.1.17':
|
||||
resolution: {integrity: sha512-YbwQ0QfVj0lxkKQhdIIgk14ZSVWDqGk1J8nNSN6SLjf36sVv58Ma5ro+dtQua8wj3l2Ub7JJCVFixEhKtYc/rQ==}
|
||||
peerDependencies:
|
||||
@@ -7012,6 +7041,10 @@ packages:
|
||||
resolution: {integrity: sha512-Z7Fh2nVQSb2d+poDViM063ix2ZGt9jmY1nWhPfHBOK2Hgnb/OW3P4Et3P/81SEej0J7QbWtJqxO05h8QYfK7LQ==}
|
||||
hasBin: true
|
||||
|
||||
fastify-ip@2.0.0:
|
||||
resolution: {integrity: sha512-7mQyAc7sapawpiriEFoJyQIs41nNIO42UCzgMKrjNGsIegnevj2VhOlXLLTa+q7cxXfJ5fDGmOAdQpaIgA9ObA==}
|
||||
engines: {node: '>=20.x'}
|
||||
|
||||
fastify-plugin@5.0.1:
|
||||
resolution: {integrity: sha512-HCxs+YnRaWzCl+cWRYFnHmeRFyR5GVnJTAaCJQiYzQSDwK9MgJdyAsuL3nh0EWRCYMgQ5MeziymvmAhUHYHDUQ==}
|
||||
|
||||
@@ -13459,6 +13492,15 @@ snapshots:
|
||||
'@tybys/wasm-util': 0.10.1
|
||||
optional: true
|
||||
|
||||
'@nest-lab/throttler-storage-redis@1.2.0(@nestjs/common@11.1.17(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.17)(@nestjs/throttler@6.5.0(@nestjs/common@11.1.17(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.17)(reflect-metadata@0.2.2))(ioredis@5.10.1)(reflect-metadata@0.2.2)':
|
||||
dependencies:
|
||||
'@nestjs/common': 11.1.17(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2)
|
||||
'@nestjs/core': 11.1.17(@nestjs/common@11.1.17(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/websockets@11.1.17)(reflect-metadata@0.2.2)(rxjs@7.8.2)
|
||||
'@nestjs/throttler': 6.5.0(@nestjs/common@11.1.17(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.17)(reflect-metadata@0.2.2)
|
||||
ioredis: 5.10.1
|
||||
reflect-metadata: 0.2.2
|
||||
tslib: 2.8.1
|
||||
|
||||
'@nestjs-labs/nestjs-ioredis@11.0.4(@nestjs/common@11.1.17(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.17)(ioredis@5.10.1)':
|
||||
dependencies:
|
||||
'@nestjs/common': 11.1.17(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2)
|
||||
@@ -13639,6 +13681,12 @@ snapshots:
|
||||
'@nestjs/core': 11.1.17(@nestjs/common@11.1.17(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/websockets@11.1.17)(reflect-metadata@0.2.2)(rxjs@7.8.2)
|
||||
tslib: 2.8.1
|
||||
|
||||
'@nestjs/throttler@6.5.0(@nestjs/common@11.1.17(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.17)(reflect-metadata@0.2.2)':
|
||||
dependencies:
|
||||
'@nestjs/common': 11.1.17(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2)
|
||||
'@nestjs/core': 11.1.17(@nestjs/common@11.1.17(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/websockets@11.1.17)(reflect-metadata@0.2.2)(rxjs@7.8.2)
|
||||
reflect-metadata: 0.2.2
|
||||
|
||||
'@nestjs/websockets@11.1.17(@nestjs/common@11.1.17(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.17)(@nestjs/platform-socket.io@11.1.17)(reflect-metadata@0.2.2)(rxjs@7.8.2)':
|
||||
dependencies:
|
||||
'@nestjs/common': 11.1.17(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2)
|
||||
@@ -18068,6 +18116,10 @@ snapshots:
|
||||
path-expression-matcher: 1.2.0
|
||||
strnum: 2.2.1
|
||||
|
||||
fastify-ip@2.0.0:
|
||||
dependencies:
|
||||
fastify-plugin: 5.1.0
|
||||
|
||||
fastify-plugin@5.0.1: {}
|
||||
|
||||
fastify-plugin@5.1.0: {}
|
||||
|
||||
Reference in New Issue
Block a user