Files
wekan/server/lib/renderExternalExport.js
T
Lauri Ojansivu 7858d84e12 Import and export many boards at once for every format, and document each format in its own directory.
Import many boards: on the import page of every source, several export
files, or one .zip holding them, each become their own board through the
same path a single import of that file takes, and the page lists what each
file became (models/lib/importManyFiles.js). A .zip that is itself one
export (Vikunja, Notion, Plane, WeKan with attachments) stays one board.
One board per project: for the generalized importer, each swimlane the
import would make - a project, folder or list of the tool - becomes its own
board (models/lib/importSplit.js), so an export of a whole app imports as
many boards, as a Trello .zip does. Kanri's all-data export now reads every
board, not only the first, so it splits into one board per Kanri board.

Export all boards: All Boards sidebar, or Multi-Selection for the selected
boards, downloads every board the user may export in one format, each
checked as its own export is. Excel is one workbook with a sheet per board,
named after the board; every other format is a .zip with one file per board
(server/routes/exportAllBoards.js). The per-format bytes are made in one
place, server/lib/renderExternalExport.js, for the board route and this.

A WeKan .zip export imports as a new board from All Boards, unpacked on the
server with its attachments (it was refused in the browser). api.py gains
importboardsfrom and exportallboards, sends every source in the shape the
import page sends, and fetches Excel, PDF, CSV and TSV exports from their
own routes and writes them as bytes.

Fixed while documenting: a Trello Butler rule's list name kept its case,
so the rule fires; the HTML export fetches the board JSON by URL instead of
a link the export popup no longer has; Tasks.org exports time spent;
Nextcloud Deck's done flag marks the due date done.

docs/Features/ImportExport has a directory per format with the steps to
import and export it, one board and many, and its details, moved from
Format-Coverage.md, which is now the index and the shared contract.
tests/importExportDocsCoverage.test.cjs fails when a format has no page.

Thanks to xet7 !
2026-10-09 10:33:37 +03:00

48 lines
2.8 KiB
JavaScript

// One board in one external format (the export menu's tool list), as the
// bytes the export route sends: models/export.js serves it for one board, and
// server/lib/exportAllBoards.js writes it for every board into one .zip.
// Returns { json } for a JSON document - sent through sendJsonResult, which
// redacts admin-only custom fields - or { contentType, body } for a file of
// its own (text, a workbook or an archive).
const { buildExternalExport } = require('/models/lib/externalExporters');
const XLSX = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
// Markdown, the Leo outline (XML), todo.txt, Taskwarrior's JSON and the other
// text formats are files of their own, sent as the formatter wrote them.
const TEXT_TYPES = { markdown: 'text/markdown', leo: 'application/xml', todotxt: 'text/plain',
taskwarrior: 'application/json', focalboard: 'application/x-ndjson', todoist: 'text/csv', meistertask: 'text/csv',
obsidian: 'text/markdown', linear: 'text/csv', ticktick: 'text/csv', clickup: 'text/csv', nullboard: 'application/json',
pivotal: 'text/csv', redmine: 'text/csv', notion: 'text/csv', superproductivity: 'application/json', quire: 'text/csv',
opml: 'text/x-opml', orgmode: 'text/x-org' };
// The tools whose import file is an Excel workbook, and the module writing it.
const WORKBOOKS = {
wrike: ['/server/lib/wrikeWorkbook', 'writeWrikeWorkbook'], // models/lib/wrikeFormat.js
monday: ['/server/lib/mondayWorkbook', 'writeMondayWorkbook'], // models/lib/mondayFormat.js
teamwork: ['/server/lib/teamworkWorkbook', 'writeTeamworkWorkbook'], // models/lib/teamworkFormat.js
businessmap: ['/server/lib/businessmapWorkbook', 'writeBusinessmapWorkbook'], // models/lib/businessmapFormat.js
planner: ['/server/lib/plannerWorkbook', 'writePlannerWorkbook'], // models/lib/plannerFormat.js
};
async function renderExternalExport(boardId, format, fields) {
const built = await buildExternalExport(boardId, format, fields);
if (TEXT_TYPES[format]) {
return { contentType: `${TEXT_TYPES[format]}; charset=utf-8`, body: String(built == null ? '' : built) };
}
// Vikunja's export is a .zip of data.json, filters.json and VERSION
// (models/lib/vikunjaFormat.js); the HTML is made after the export
// boundary has checked the text it is made from.
if (format === 'vikunja') {
const { vikunjaArchiveFiles } = require('/models/lib/vikunjaFormat');
return { contentType: 'application/zip', body: require('/server/lib/vikunjaArchive').writeVikunjaArchive(vikunjaArchiveFiles(built)) };
}
if (WORKBOOKS[format]) {
const [path, writer] = WORKBOOKS[format];
return { contentType: XLSX, body: await require(path)[writer](built) };
}
// Every other format is one JSON document - Kanri's board export
// (models/lib/kanriFormat.js) among them.
return { json: built };
}
module.exports = { renderExternalExport };