Files
wekan/tests/trelloLiveStreaming.test.cjs
T
Lauri Ojansivu ddc025c24d Stream live Trello import attachments from Trello into storage as each card is made.
The live Trello import, and a Trello .json import with saved credentials,
downloaded every uploaded attachment of the board first - each read whole,
up to 256 MB - and kept them all on the board as base64 until it was made.
TrelloCreator now gets a streamer: each attachment is downloaded when the
creator reaches it and streamed into storage, one at a time. The download is
the same - the URL check, the credential only for Trello's own hosts, every
redirect validated and pinned - through fetchSafe's new stream mode, which
hands the body on as a stream with the same byte limit counted as it flows.
Removed from TODO Later.

Thanks to markusst1982 and xet7 !
2026-10-09 23:05:47 +03:00

28 lines
1.7 KiB
JavaScript

'use strict';
// The live Trello import streams each attachment from Trello into storage as
// the creator reaches it, instead of downloading every file of the board
// first and keeping it as base64 (#6745). Run: node tests/trelloLiveStreaming.test.cjs
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const read = file => fs.readFileSync(path.join(__dirname, '..', file), 'utf8');
const guard = read('server/lib/ssrfGuard.js');
// fetchSafe's stream mode keeps the byte limit, counted as the bytes flow.
assert.match(guard, /if \(options\.stream\) \{[\s\S]*?if \(streamed > maxBytes\) return done\(new Error\(`outbound response exceeds \$\{maxBytes\} bytes`\)\);/);
assert.match(guard, /resolve\(\{ status: res\.statusCode, ok: res\.statusCode >= 200 && res\.statusCode < 300, headers, body \}\);/);
const live = read('server/trelloApiImport.js');
assert.match(live, /trelloFetch\(url, \{ headers: trelloAuthHeaders\(url, key, token\), stream: true \}, \{ untrusted: true \}\)/);
assert.match(live, /creator\.attachmentStream = trelloAttachmentStreamer\(creds\.key, creds\.token\);/);
assert.match(live, /if \(res\.body && typeof res\.body\.destroy === 'function'\) res\.body\.destroy\(\);/, 'a retried stream is let go');
// Negative: no attachment is downloaded whole and kept as base64 any more.
assert.doesNotMatch(live, /inlineAttachments|downloadAttachmentBase64|att\.file = base64/);
const zip = read('server/routes/importTrelloZip.js');
assert.match(zip, /trelloAttachmentStreamer\(creds\.key, creds\.token\)/, 'the single-board .json import streams them too');
assert.match(zip, /if \(attachmentStream\) creator\.attachmentStream = attachmentStream;/);
console.log('trelloLiveStreaming: 8 checks passed');