Files
wekan/models/lib/importSourceShape.js
T
Lauri Ojansivu 286ed906a9 Import and export Leo .leo outlines.
The Leo literate editor's XML outline is a new import source and export
format: top-level nodes are lists, their children are cards with the node
body as the description and a marked node as done, and deeper nodes are
checklists. Clones keep their headline and children. The raw XML is parsed
server-side with htmlparser2 in XML mode (no DTDs or external entities), a
self-clone cannot loop and a clone bomb is refused at 100000 nodes, and the
parsed tasks then pass the shared import sanitizer.

Thanks to xet7 !
2026-09-29 18:41:21 +03:00

24 lines
1.6 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 'csv': valid = Array.isArray(value) && value.length > 0 && value.every(Array.isArray); break;
case 'excel': valid = typeof value?.excelBase64 === 'string' && value.excelBase64.length > 0; break;
case 'markdown': valid = typeof value === 'string' && value.trim().length > 0; break;
case 'leo': valid = typeof value === 'string' && /<leo_file[\s>]/.test(value); break;
}
if (!valid) throw new Error(`Invalid ${source} import document shape`);
}