Files
wekan/models/lib/importSourceShape.js
T
Lauri Ojansivu dd7baeec54 Import and export boards as todo.txt.
todo.txt (github.com/todotxt/todo.txt) is the one-task-per-line format
the todo.txt CLI and many compatible apps share, and WeKan read and
wrote neither. It now imports from the import picker and exports from
the board's export menu. A completed task goes to Done; priority becomes
a priority:A label; creation and completion dates become the card's
creation and end dates; +project and @context become labels; due: and
t: become due and start dates; WeKan's list: extension keeps list names
across a round trip. Other key:value pairs stay in the title, a
malformed date is reported instead of guessed, and a completion date is
written only with a creation date, as the format requires. todo.txt has
no descriptions, comments or members, so an export leaves them out.

tests/todoTxt.test.cjs runs the specification's examples, the round trip
and the negatives; the format guards learn the new format and a
Playwright case imports a todo.txt through the page. The new
instruction text is in English, pending translation.

Thanks to xet7 !
2026-09-30 02:54:25 +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': case 'todotxt': 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`);
}