mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 20:45:00 -05:00
A JavaScript string cannot be longer than about 512 MB, so reading an uploaded JSON export with readFile and JSON.parse could not read a larger one at all. server/lib/streamJson.js builds the value from the file as it is read - every escape, surrogate pairs and chunk boundaries anywhere, the same value and the same refusals as JSON.parse, a __proto__ key as an own property, nesting bounded. A Mattermost bulk export is read a line at a time; the other text formats are read as one text up to 256 MB and refused with that reason beyond it. Thanks to xet7 !
46 lines
2.1 KiB
JavaScript
46 lines
2.1 KiB
JavaScript
// Server-only: the mail, calendar, chat and note imports of the Import page,
|
|
// from what the page sent (text, parsed JSON, or a .zip as { zipBase64 }) to
|
|
// the normalized board KanboardCreator writes. The decoders that are not for
|
|
// the client - mailparser, htmlparser2, unzipper - are only reached here.
|
|
import { parseMailMessages } from '/models/lib/mailFormat';
|
|
import { enexBoard } from '/models/lib/enexFormat';
|
|
import { parseGoogleTakeout } from '/models/lib/googleTakeoutFormat';
|
|
import { parseSlackExport } from '/models/lib/chatExportFormats';
|
|
import { EXTERNAL_PARSERS } from '/models/lib/externalParsers';
|
|
|
|
const text = value => {
|
|
if (typeof value !== 'string') throw new Error('Paste or choose the exported file');
|
|
return value;
|
|
};
|
|
|
|
export async function parseMessageImport(source, value) {
|
|
switch (source) {
|
|
case 'mail': {
|
|
// A mailbox streamed to the local disk is read a message at a time.
|
|
if (value && typeof value.mboxFile === 'string') {
|
|
const { messages, skipped } = await require('./mailImport').decodeMailFile(value.mboxFile);
|
|
const board = parseMailMessages(messages, { name: 'Imported mail' });
|
|
if (skipped) board.unsupported.push({ path: '/messages', reason: `${skipped} message(s) larger than 32 MB are not imported` });
|
|
return board;
|
|
}
|
|
return parseMailMessages(await require('./mailImport').decodeMail(text(value)), { name: 'Imported mail' });
|
|
}
|
|
case 'evernote': {
|
|
const { notes, cutOff } = require('./enexImport').readEnex(text(value));
|
|
return enexBoard(notes, { cutOff });
|
|
}
|
|
case 'slack':
|
|
return parseSlackExport(await require('./chatArchives').readSlackExport(value));
|
|
case 'googletakeout':
|
|
return parseGoogleTakeout(await require('./chatArchives').readGoogleTakeout(value));
|
|
case 'mattermost':
|
|
return EXTERNAL_PARSERS.mattermost(value && Array.isArray(value.jsonLines) ? value : text(value));
|
|
case 'ical': case 'whatsapp':
|
|
return EXTERNAL_PARSERS[source](text(value));
|
|
case 'telegram': case 'discord':
|
|
return EXTERNAL_PARSERS[source](value);
|
|
default:
|
|
throw new Error(`Unknown import source: ${source}`);
|
|
}
|
|
}
|