Files
wekan/server/lib
Lauri Ojansivu cd74045a9f Attachment slideshow: Outlook .msg and OpenDocument are converted once, a piece at a time, into rows read a screen at a time.
An Outlook .msg (a Compound File of scattered sectors) and an
OpenDocument (a ZIP whose text is a compressed content.xml) cannot be
read a row at a time as they are: the slideshow read a .msg whole, up to
32 MB, and an OpenDocument as far as it was scrolled. Now the server
converts each the first time it is opened (server/lib/
attachmentPreviewStore.js):

- the original is read from its own storage in 64 KB byte ranges, never
  whole; of a .msg only the sector tables are kept and the text streams
  (models/lib/outlookMsgFormat.js openCompoundFile, outlookMsgRows),
  attachment data is never read; of an OpenDocument only content.xml is
  inflated and parsed as a stream (models/lib/zipDirectory.js and
  odfBlocks.js, moved from the client so both share them);
- what is found is written as rows - one JSON object a line - with an
  index of where each starts, to temporary names renamed when complete,
  in attachment-previews/ under the files root; made again when the file
  changes and removed with the attachment; two conversions at a time;
- one preview takes at most 512 MB of the server's disk, and a row
  repeated more than 100,000 times is written that many times.

The parts are served at /cdn/storage/attachments/<id>/preview-meta,
-index and -rows, after every check the original has, with Range, as
application/octet-stream, nosniff and a sandboxing CSP. Two path
segments, as /thumbnail: Meteor-Files answers every longer path under
/cdn/storage itself. The slideshow reads them through
client/lib/attachmentRecords.js into IndexedView, whose scrollbar is
exactly the rows; only the visible rows are fetched and drawn, and no
viewer reads a file whole any more.

tests/attachmentPreviewStore.test.cjs reads a .msg with a 5 MB
attachment through ranges and finds it the same as the whole-file
reader without reading the attachment, a 60,000-line body and an
HTML-only body as rows, an OpenDocument's 6 MB picture never read, the
repeat and disk guards, made once and removed, and the route after
every check. attachment-rich-preview.e2e.js opens a 100,000-line .msg
in Chromium and finds only ranged preview parts fetched, the last line
at the end of the scrollbar, and the preview refused without signing in.

Thanks to xet7 !
2026-11-22 12:58:26 +02:00
..