mirror of
https://github.com/wekan/wekan.git
synced 2026-11-20 14:45:01 -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 !
60 lines
4.8 KiB
JavaScript
60 lines
4.8 KiB
JavaScript
// Shape validation before creating a board. Unknown/empty objects must not
|
|
// report a successful import which silently contains no source records.
|
|
export function validateImportSourceShape(source, value) {
|
|
const arrayAt = (object, key) => object && Array.isArray(object[key]);
|
|
let valid = false;
|
|
switch (source) {
|
|
case 'wekan': case 'trello': valid = arrayAt(value, 'cards') && arrayAt(value, 'lists'); break;
|
|
case 'kanboard': valid = arrayAt(value, 'tasks'); break;
|
|
case 'jira': valid = arrayAt(value, 'issues'); break;
|
|
case 'github': case 'gitlab': case 'gitea': case 'forgejo':
|
|
valid = Array.isArray(value) || arrayAt(value, 'issues'); break;
|
|
case 'deck': valid = arrayAt(value, 'stacks') || arrayAt(value?.board, 'stacks'); break;
|
|
case 'openproject': valid = Array.isArray(value) || arrayAt(value, 'elements') || arrayAt(value?._embedded, 'elements'); break;
|
|
case 'asana': valid = Array.isArray(value) || arrayAt(value, 'data'); break;
|
|
case 'zenkit': valid = Array.isArray(value) || arrayAt(value, 'items')
|
|
|| (arrayAt(value, 'elements') && (arrayAt(value, 'entries') || arrayAt(value, 'listEntries'))); break;
|
|
case 'tasksorg': valid = arrayAt(value?.data, 'tasks'); break;
|
|
case 'csv': valid = Array.isArray(value) && value.length > 0 && value.every(Array.isArray); break;
|
|
case 'taiga': valid = arrayAt(value, 'user_stories'); break;
|
|
case 'kanri': valid = arrayAt(value, 'columns') || arrayAt(value, 'boards'); break;
|
|
// What server/apiImport.js fetches (models/lib/apiImport/<key>.js).
|
|
case 'planka': valid = Boolean(value?.planka?.item) && typeof value.planka.included === 'object'; break;
|
|
case 'mstodo': case 'googletasks': valid = arrayAt(value, 'lists'); break;
|
|
case 'kanbanflow': valid = Boolean(value?.board) && arrayAt(value, 'tasks'); break;
|
|
case 'basecamp': valid = Boolean(value?.project) && (arrayAt(value, 'cardTables') || arrayAt(value, 'todolists')); break;
|
|
case 'googlekeep': valid = arrayAt(value, 'notes'); break;
|
|
// Vikunja: the export .zip as { zipBase64 }, or the text of its data.json.
|
|
// Notion: the Markdown & CSV export .zip as { zipBase64 }, or one database CSV.
|
|
case 'notion':
|
|
case 'vikunja': valid = (typeof value?.zipBase64 === 'string' && value.zipBase64.length > 0)
|
|
|| typeof value?.zipFile === 'string'
|
|
|| (typeof value === 'string' && value.trim().length > 0); break;
|
|
// Plane: the export .zip as { zipBase64 }, a workbook as { xlsxBase64 },
|
|
// or the text of a JSON or CSV export file.
|
|
case 'plane': valid = (typeof value?.zipBase64 === 'string' && value.zipBase64.length > 0)
|
|
|| typeof value?.zipFile === 'string'
|
|
|| (typeof value?.xlsxBase64 === 'string' && value.xlsxBase64.length > 0)
|
|
|| (typeof value === 'string' && value.trim().length > 0); break;
|
|
case 'excel': case 'planner': case 'monday': case 'wrike': case 'teamwork': case 'businessmap': valid = typeof value?.excelBase64 === 'string' && value.excelBase64.length > 0; break;
|
|
case 'markdown': case 'todotxt': case 'taskwarrior': case 'focalboard': case 'todoist': case 'meistertask': case 'obsidian': case 'linear': case 'ticktick': case 'clickup': case 'nullboard': case 'pivotal': case 'redmine': case 'superproductivity': case 'quire': case 'orgmode': valid = typeof value === 'string' && value.trim().length > 0; break;
|
|
case 'leo': valid = typeof value === 'string' && /<leo_file[\s>]/.test(value); break;
|
|
// Mail, calendar, chat and note exports (models/lib/mailFormat.js,
|
|
// icalendarFormat.js, chatExportFormats.js, enexFormat.js,
|
|
// googleTakeoutFormat.js).
|
|
case 'mail': valid = (typeof value === 'string' && value.trim().length > 0) || typeof value?.mboxFile === 'string'; break;
|
|
case 'whatsapp': valid = typeof value === 'string' && value.trim().length > 0; break;
|
|
case 'ical': valid = typeof value === 'string' && /BEGIN:VCALENDAR/i.test(value); break;
|
|
case 'mattermost': valid = (typeof value === 'string' && /"type"\s*:\s*"version"/.test(value))
|
|
|| (Array.isArray(value?.jsonLines) && value.jsonLines.some(line => line && line.type === 'version')); break;
|
|
case 'evernote': valid = typeof value === 'string' && /<en-export[\s>]/.test(value); break;
|
|
case 'telegram': valid = arrayAt(value, 'messages') || arrayAt(value?.chats, 'list'); break;
|
|
case 'discord': valid = (Array.isArray(value) ? value : [value]).every(e => e && e.channel && Array.isArray(e.messages)); break;
|
|
// A .zip sent in the call, or one streamed to the local disk (zipFile).
|
|
case 'slack': case 'googletakeout': valid = (typeof value?.zipBase64 === 'string' && value.zipBase64.length > 0)
|
|
|| typeof value?.zipFile === 'string'; break;
|
|
case 'opml': valid = typeof value === 'string' && /<opml[\s>]/.test(value); break;
|
|
}
|
|
if (!valid) throw new Error(`Invalid ${source} import document shape`);
|
|
}
|