From b6478fee84d648565814783c9810fe0665aad160 Mon Sep 17 00:00:00 2001 From: Philipinho <16838612+Philipinho@users.noreply.github.com> Date: Tue, 3 Mar 2026 13:57:10 +0000 Subject: [PATCH] fix imports --- .../services/import-attachment.service.ts | 35 ++++++++++++++++--- .../import/utils/import-formatter.ts | 34 ++++++++++++++++++ 2 files changed, 64 insertions(+), 5 deletions(-) diff --git a/apps/server/src/integrations/import/services/import-attachment.service.ts b/apps/server/src/integrations/import/services/import-attachment.service.ts index bba517d0..a797ecc6 100644 --- a/apps/server/src/integrations/import/services/import-attachment.service.ts +++ b/apps/server/src/integrations/import/services/import-attachment.service.ts @@ -14,6 +14,7 @@ import { getAttachmentFolderPath } from '../../../core/attachment/attachment.uti import { AttachmentType } from '../../../core/attachment/attachment.constants'; import { unwrapFromParagraph } from '../utils/import-formatter'; import { resolveRelativeAttachmentPath } from '../utils/import.utils'; +import { imageDimensionsFromData } from 'image-dimensions'; import { load } from 'cheerio'; import pLimit from 'p-limit'; import { InjectQueue } from '@nestjs/bullmq'; @@ -271,15 +272,37 @@ export class ImportAttachmentService { continue; } - const { attachmentId, apiFilePath } = processFile(relPath); + const { attachmentId, apiFilePath, abs } = processFile(relPath); - const width = $img.attr('width') ?? '100%'; + let width = $img.attr('width'); + const height = $img.attr('height'); const align = $img.attr('data-align') ?? 'center'; + if (!width) { + try { + const buf = await fs.readFile(abs); + const natural = imageDimensionsFromData(new Uint8Array(buf)); + if (natural) { + width = height + ? String( + Math.round((natural.width / natural.height) * Number(height)), + ) + : String(natural.width); + } + } catch { + /* empty */ + } + + if (!width) { + width = '600'; + } + } + $img .attr('src', apiFilePath) .attr('data-attachment-id', attachmentId) .attr('width', width) + .attr('height', height) .attr('data-align', align); unwrapFromParagraph($, $img); @@ -420,7 +443,7 @@ export class ImportAttachmentService { const { attachmentId, apiFilePath, abs } = processFile(relPath); const fileName = path.basename(abs); - const width = $oldDiv.attr('data-width') || '100%'; + const width = $oldDiv.attr('data-width') || '600'; const align = $oldDiv.attr('data-align') || 'center'; const $newDiv = $('