Repository navigation
fix: confluence drawio import - #1518
Conversation
WalkthroughAdds Draw.io (mxfile) detection and PNG pairing, generates SVG diagram attachments, reworks upload pipeline with retries/deduplication, consolidates HTML/media rewriting into a single DOM traversal with caching, supports optional pageAttachments, appends unreferenced attachments, and updates an EE submodule pointer. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Caller
participant ImportSvc as ImportAttachmentService
participant DOM as DOM Parser
participant FS as File System
participant Upl as Upload Service/API
Caller->>ImportSvc: processAttachments(html, pageRelativePath, extractDir, pageId, fileTask, attachmentCandidates, pageAttachments?)
ImportSvc->>ImportSvc: analyzeAttachments(attachmentCandidates, pageAttachments?)
note right of ImportSvc: detect Draw.io ↔ PNG pairs
loop For each Draw.io pair
ImportSvc->>FS: read drawio (+ optional png)
ImportSvc->>ImportSvc: createDrawioSvg(...)
ImportSvc->>Upl: uploadWithRetry(svg stream, mime=image/svg+xml)
Upl-->>ImportSvc: attachmentId, apiFilePath
ImportSvc->>ImportSvc: drawioSvgMap[originals] = {id, apiFilePath}
end
ImportSvc->>DOM: parse(html)
note right of DOM: single traversal of img/video/a[src|href]
loop DOM traversal
ImportSvc->>ImportSvc: getCachedResolvedPath / getCachedStat
alt matched Draw.io or paired PNG
ImportSvc->>DOM: replace node with div[data-type="drawio"][data-src=apiFilePath]
else normal asset
ImportSvc->>Upl: uploadOnce/uploadWithRetry (deduped)
Upl-->>ImportSvc: attachmentId, apiFilePath
ImportSvc->>DOM: rewrite src/href to apiFilePath
end
ImportSvc->>ImportSvc: usedAttachmentIds += attachmentId
end
alt Append missing attachments
ImportSvc->>DOM: append unreferenced drawio/pageAttachments
end
ImportSvc-->>Caller: return updated HTML
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (8)
apps/server/src/integrations/import/services/import-attachment.service.ts (8)
119-126: Use per-diagram filenames and surface them in data-title for better UX and debugging.Avoid a generic diagram.drawio.svg for all diagrams; use a sanitized base name and show it in the rendered node.
Apply:
- const fileName = 'diagram.drawio.svg'; + const safeBase = sanitizeFileName(pair.baseName || 'diagram'); + const fileName = `${safeBase}.drawio.svg`; @@ - drawioSvgMap.set(drawioHref, { attachmentId, apiFilePath, fileName }); + drawioSvgMap.set(drawioHref, { attachmentId, apiFilePath, fileName }); @@ - .attr('data-title', 'diagram') + .attr('data-title', drawioSvg.fileName) @@ - .attr('data-title', 'diagram') + .attr('data-title', drawioSvg.fileName) @@ - .attr('data-title', 'diagram') + .attr('data-title', drawioSvg.fileName)Also applies to: 165-172, 285-289, 385-389, 456-460
349-371: Honor Draw.io SVG mapping when rewriting existing div[data-type="drawio"].If a drawio div references a paired file, reuse the generated SVG instead of re-uploading the raw file.
- } else if (dataType === 'excalidraw' || dataType === 'drawio') { + } else if (dataType === 'excalidraw' || dataType === 'drawio') { const rawSrc = cleanUrlString($el.attr('data-src') ?? ''); if (!rawSrc || rawSrc.startsWith('http')) continue; const relPath = getCachedResolvedPath(rawSrc); if (!relPath) continue; + // Prefer generated SVG if this is part of a Draw.io pair + const svg = drawioSvgMap.get(relPath); + if (dataType === 'drawio' && svg) { + const $newDiv = $('<div>') + .attr('data-type', 'drawio') + .attr('data-src', svg.apiFilePath) + .attr('data-title', svg.fileName) + .attr('data-width', $el.attr('data-width') || '100%') + .attr('data-align', $el.attr('data-align') || 'center') + .attr('data-attachment-id', svg.attachmentId); + $el.replaceWith($newDiv); + unwrapFromParagraph($, $newDiv); + continue; + } + const { attachmentId, apiFilePath, abs } = processFile(relPath); const stat = await getCachedStat(abs); const fileName = path.basename(abs);
237-248: Avoid non-null assertion in cache read.Return type is string | null; using ! is unnecessary and brittle.
- if (resolvedPathCache.has(rawPath)) { - return resolvedPathCache.get(rawPath)!; - } + if (resolvedPathCache.has(rawPath)) { + return resolvedPathCache.get(rawPath) ?? null; + }
250-261: Type stat cache precisely (fs.Stats) and import type.Improves IntelliSense and prevents accidental misuse.
-import { Readable } from 'stream'; +import { Readable } from 'node:stream'; +import type { Stats } from 'node:fs'; @@ - const statCache = new Map<string, any>(); + const statCache = new Map<string, Stats>(); @@ - const getCachedStat = async (absPath: string) => { + const getCachedStat = async (absPath: string): Promise<Stats> => {
153-161: Record a more useful identifier on SVG upload failure.File name repeats across diagrams; include storage path for actionable logs.
- uploadStats.failedFiles.push(fileName); + uploadStats.failedFiles.push(storageFilePath);
726-769: Idempotency between storage upload and DB insert.If storage succeeds and DB insert fails, retries re-upload the same object. Consider short-circuiting on “object exists” or making the DB insert idempotent (upsert on id) to avoid wasted bandwidth and inconsistent states.
Would you like a follow-up patch adding an upsert on attachments.id and skipping upload when the path already exists (via a lightweight HEAD check in StorageService)?
660-695: Large-file guard when embedding PNG into SVG.Reading entire PNGs and mxfiles into memory can spike RAM on big attachments. Consider size checks (e.g., cap at ~20MB) and stream-to-base64 if needed.
Do you expect very large diagrams from Confluence exports in your datasets? If yes, I can add a size threshold with a clear warning and fallback behavior.
576-585: Simplify Draw.io detection.You already rely on mimeType === application/vnd.jgraph.mxfile; the extension guard here is odd and can hide true drawio files with unconventional names. Prefer trusting the MIME (or also accept .drawio extension when MIME is missing).
- if (mimeType === 'application/vnd.jgraph.mxfile') { - const ext = fileNameLower.substring(fileNameLower.lastIndexOf('.')); - if (!nonDrawioExtensions.has(ext)) { - drawioFiles.push(attachment); - } else { - //Skipped non-Draw.io file with mxfile MIME.}`, - } - } + if (mimeType === 'application/vnd.jgraph.mxfile' || fileNameLower.endsWith('.drawio')) { + drawioFiles.push(attachment); + }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
apps/server/src/integrations/import/services/import-attachment.service.ts(10 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
apps/server/src/integrations/import/services/import-attachment.service.ts (5)
apps/server/src/core/attachment/attachment.utils.ts (1)
getAttachmentFolderPath(54-70)apps/server/src/integrations/import/utils/import.utils.ts (1)
resolveRelativeAttachmentPath(28-43)apps/server/src/integrations/import/utils/file.utils.ts (1)
cleanUrlString(183-187)apps/server/src/integrations/import/utils/import-formatter.ts (1)
unwrapFromParagraph(196-211)apps/server/src/common/helpers/file.helper.ts (1)
getMimeType(4-7)
🔇 Additional comments (1)
apps/server/src/integrations/import/services/import-attachment.service.ts (1)
51-51: No action needed forpageAttachmentsparameter. ExistingprocessAttachmentscall in file-task.service.ts continues to compile with onlyhtmlandpageRelativePath(no breaking change).
4231ba9 Merge commit '042836cb6d7cc1f71af3ce44c7957f8abbbf8f25' into feat/aar_edition 042836c sync 4f1f0ba fix 3164b69 feat: api keys management (EE) (docmost#1665) 16c1e86 fix comment space c9b1cad sync bf8cf62 feat: Typesense search driver (EE) (docmost#1664) 5a2e16a Merge commit '31350303760163384113bf49d07127e886f94907' into feat/aar_edition 3bc710d Adds CLAUDE.md documentation 16914f1 Block search for non-indexed shares ca75e29 Set default page mode to Read 3135030 fix editor converter (docmost#1647) 3fae41a fix: editor performance improvements (docmost#1648) b50e256 sync 1f3b0c7 cloud fix 3c4cab0 v0.23.2 4de25a8 invalidate queries on space deletion cf5bbb1 fix import html processing ac17521 sync 9ac180f fix: enhance page import (docmost#1570) 46669fe (cloud) disable page sharing in trial mode fe6ecdf fix: update combobox props in SpaceSelect component (docmost#1564) 04ae1d7 Allow lastColumnResizable in table 1280f96 feat: implement space and workspace icons (docmost#1558) 61d1cf8 fix: reset file inputs after import f413720 - sync - reinstantiate S3 client to fix file upload errors during import - delete import zip file after use 8e16ad9 v0.23.1 7ada3cb fix: page import task (docmost#1551) 47c5417 sync dc06502 sync 091e790 fix attachment search in cloud ae24ea2 v0.23.0 9df6061 lock file 31053e2 update mermaid eb8e850 use debug c99bfb8 make print better 26ea04e sync 6cc58c5 sync 7d2ff34 UI fixes b08d37f fix d43ee77 remove debug log 5d91eb4 feat: queue imported attachments for indexing 3e9f6b1 Remove version from docker-compose.yml [deprecated] (docmost#1011) db55de9 feat: progressive web app (docmost#614) 1919eba New Crowdin updates (docmost#1522) 7951b2e New Crowdin updates (docmost#1509) 73b78f6 more translations cf7534d fix version display adec36d fix: adjust margins - use default browser highlight background f9e1080 sync 00e499b Fixing extra page bug on print (docmost#1478) 5ee6e46 checkbox aligned to text (docmost#1486) 1f797c3 fix: confluence drawio import (docmost#1518) f12866c feat(EE): full-text search in attachments (docmost#1502) dcbb65d feat(EE): LDAP integration (docmost#1515) 5968764 feat: emoji callout icon (docmost#1323) 242fb6b fix: set mermaid theme based on computed color scheme (docmost#1438) 74cd890 feat(EE): implement SSO group sync for SAML and OIDC (docmost#1452) 509622a ignore type error 937386e fix: hide table handles in readonly mode 60a373f fix: readonly editor table responsiveness 73ee6ee feat: subpages (child pages) list node (docmost#1462) 7d1e5bc feat: table row/column drag and drop (docmost#1467) aa58e27 fix: exclude deleted pages (docmost#1494) 08135a2 sync d92a942 sync 5012a68 sync 5a33777 feat: debug mode env variable (docmost#1450) 3b85f4b fix: enforce C collation for page position ordering to ensure consistent behavior in Postgres 17+ (docmost#1446) cb2a039 fix: invalidate trashed page from tree state 95b7be6 fix: hide trash from can view permission (docmost#1445) b0c5572 fix nested taskList in markdown export (docmost#1443) dddfd48 feat: add attachments support for single page exports (docmost#1440) aa6eec7 fix: exclude trashed pages from position generation 97a7701 fix local storage copy function (docmost#1442) b97eb85 sync git-subtree-dir: vendor/app git-subtree-split: 4231ba9
* POC * WIP - working * WIP * WIP * sync * fix drawio preview image
Summary by CodeRabbit
New Features
Improvements
Bug Fixes