Files
wekan/tests/attachmentViewerLayout.test.cjs
T
Lauri Ojansivu 373980ac8a Restore the full-featured DOCX/XLSX/PPTX viewer and native PDF preview
The minimal server-rendered GIF-slideshow document preview (added this week
to cut dependency weight) kept failing with a bare 415 - its own
rasterization dependency chain (pdf-to-img -> pdfjs-dist's optional
@napi-rs/canvas) needed three separate fixes in a single day for a missing
package, a worker path resolved into the wrong bundle directory, and a stale
stored filename, and still left a text-only fallback as the best case for a
PDF.

Restore the previous full-featured viewer instead: office-open-xml-viewer
(MIT, canvas-based, zero runtime dependencies) renders DOCX/XLSX/PPTX
client-side, and PDF goes back to the browser's own native <embed> viewer -
simpler, zero extra dependencies, and gets the browser's own zoom/search/
print for free.

The server-side full-text search this week's change introduced is kept:
server/lib/documentGif.js now does nothing but extract plain text for the
search index (indexDocumentText, triggered in the background from
Attachments.onAfterUpload) - no rendering, no HTML, no page images - so
pdf-to-img and @napi-rs/canvas are dropped entirely (nothing rasterizes a
PDF page server-side any more) while pdfjs-dist stays, now as a direct
dependency, for its text-only extraction. Searching attachment contents from
the card search box keeps working exactly as before.

Thanks to xet7 !
2026-09-10 16:59:42 +03:00

34 lines
1.4 KiB
JavaScript

const assert = require('node:assert');
const fs = require('node:fs');
const path = require('node:path');
const test = require('node:test');
const root = path.resolve(__dirname, '..');
const css = fs.readFileSync(
path.join(root, 'client/components/cards/attachments.css'),
'utf8',
);
function declarations(selector) {
const escaped = selector.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const match = new RegExp(`${escaped}\\s*\\{([^}]*)\\}`).exec(css);
assert.ok(match, `${selector} must have a CSS rule`);
return match[1];
}
test('#6612: the attachment overlay gives its viewer the available viewport', () => {
assert.match(declarations('#viewer-overlay'), /display:\s*flex/);
assert.match(declarations('#viewer-overlay'), /flex-direction:\s*column/);
assert.match(declarations('#viewer-overlay.hidden'), /display:\s*none/);
assert.match(declarations('#viewer-container'), /flex:\s*1 1 auto/);
assert.match(declarations('#viewer-content'), /flex:\s*1 1 auto/);
assert.match(declarations('#office-viewer'), /width:\s*100%/);
assert.match(declarations('#txt-viewer'), /width:\s*100%/);
});
test('#6612 negative: desktop document previews are not fixed-width columns', () => {
assert.doesNotMatch(declarations('#office-viewer'), /width:\s*\d+px/);
assert.doesNotMatch(declarations('#txt-viewer'), /width:\s*\d+px/);
assert.doesNotMatch(css, /max-width:\s*1600px[\s\S]*?#office-viewer/);
});