mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
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 !
20 lines
906 B
JavaScript
20 lines
906 B
JavaScript
'use strict';
|
|
|
|
// /cdn/storage/attachments/<id>/preview-<part>: the parts of an attachment's
|
|
// converted preview (server/lib/attachmentPreviewStore.js) - meta, index and
|
|
// rows. Two segments, like /<id>/thumbnail: Meteor-Files answers every
|
|
// /cdn/storage/<collection>/<id>/<version>/<name> path itself, so a third
|
|
// segment never reaches the file server. Pure, for the file server and
|
|
// tests/attachmentPreviewStore.test.cjs.
|
|
const PREVIEW_PARTS = ['meta', 'index', 'rows'];
|
|
|
|
// The part asked for, from the path after /cdn/storage/attachments, or null.
|
|
function previewPartOf(urlPath) {
|
|
const parts = String(urlPath || '').split('?')[0].split('/').filter(Boolean);
|
|
if (parts.length !== 2 || !parts[1].startsWith('preview-')) return null;
|
|
const part = parts[1].slice('preview-'.length);
|
|
return PREVIEW_PARTS.includes(part) ? part : null;
|
|
}
|
|
|
|
module.exports = { previewPartOf, PREVIEW_PARTS };
|