Files
wekan/tests/attachmentViewerLayout.test.cjs
T
Lauri Ojansivu d6652f19b7 Attachment slideshow: only what is on the screen is read, with no row or size limit.
The text-like viewers read a whole file (up to 32 MB) and showed at most
1000 rows or 2048 names. Now only what is on the screen is fetched and
only that is in the page (client/lib/attachmentWindow.js):

- Text, .log, CSV/TSV, source code, and JSON and Markdown larger than one
  chunk are read through HTTP Range requests in 256 KB chunks, at most 16
  kept. The scrollbar is the whole file: dragged to the middle it shows
  the middle, scrolled a little it moves row by row, at its end is the
  last row. A row ends at a newline or at the next multiple of 4096 bytes
  of the file, so rows are found the same from any byte, a 50 MB line of
  minified JSON is many rows, and no UTF-8 character is split. A server
  that ignores Range (a legacy CollectionFS attachment) is read only up
  to the bytes wanted.
- ZIP lists its names from the central directory through Range requests,
  ZIP64 too, without downloading any entry.
- tar and tar.gz, iCalendar and OpenDocument are read in order as far as
  they are scrolled - infinite scroll downwards - since compressed data
  cannot be read from its middle. An OpenDocument's content.xml is found
  in the central directory and only it is inflated and parsed as a
  stream; a sheet's rows repeated to the edge of the grid cost nothing.
- Plain text no longer goes to an <object>, which loaded it whole.

A footnote's paragraphs no longer end the OpenDocument paragraph they sit
in. tests/attachmentWindow.test.cjs drives the rows and views against a
fake Range server; the viewer and ZIP tests show no limit is left and
that only windows are fetched; attachment-rich-preview.e2e.js opens a
150,000-row CSV in Chromium and finds only 206 ranges fetched, the middle
and the last row shown, and only a screenful of rows in the page.

Thanks to xet7 !
2026-11-22 12:17:19 +02:00

37 lines
1.6 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%/);
// Plain text is read windowed in #rich-viewer now (client/lib/attachmentWindow.js),
// whose rule it shares with #zip-viewer; the <object> #txt-viewer is gone.
assert.match(declarations('#zip-viewer'), /width:\s*100%/);
assert.match(declarations('#zip-viewer'), /height:\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('#zip-viewer'), /width:\s*\d+px/);
assert.doesNotMatch(css, /max-width:\s*1600px[\s\S]*?#office-viewer/);
});