Files
wekan/server/apiImport.js
T
Lauri Ojansivu 01e88410cd Import and export Azure DevOps Boards, Microsoft Lists, Project, Outlook, Teams and OneNote.
Azure DevOps Boards: a query's "Export to CSV" is imported (Board Column or
State as lists, Board Lane as swimlanes, Title 1/2/3 tree levels as parent
cards, "Name <address>" people, regional dates, other columns as custom
fields), and a board exports as the CSV "Import from CSV" reads.

Microsoft Lists: a list's "Export to CSV" is imported (Status or Progress as
the lists, people, dates, tags, other columns as custom fields), and a board
exports as a CSV that "New list - From CSV" makes a list of.

Microsoft Project: the "XML Format" (MSPDI) plan is imported (summary tasks
as swimlanes, progress as lists, subtasks, resources, predecessors), read by
a small XML reader that never resolves a DTD or an entity, and a board
exports as a plan Project opens.

Outlook: .msg files are read without a library - the Compound File Binary
format (MS-CFB) and the message's properties (MS-OXMSG) - into the mail
import, threads and attachments included, alone or in a .zip with .eml
files; a board exports as .eml files Outlook opens. The reader was checked
against .msg files saved by Outlook.

Teams and OneNote: fetched from Microsoft Graph with the member's token
(chats and channels; notebooks with their pages' HTML, to-do boxes as a
checklist), or read from a file - Teams' personal export .tar, Graph chat
messages, and the files WeKan exports: Teams chats as Graph chat messages,
OneNote pages as Graph's create-page XHTML in a .zip.

All six are under the Microsoft heading of Import and Export, with tests,
negative tests, live tests for the two Graph imports, documentation and the
import instruction in every language. Low confidence translations include
ace, ak, ay, bm, bo, bua, chr, csb, cv, dz, ee, ff, fj, gn, gv, haw, ig, iu,
kl, ks, kok, kw, ht, hsb, fur, fo, ga, gd, ku, lld, nah, nap, rup, sah, sc,
scn, se, nd, nso, ss, om, rn, rw, sm, sn, qu, pap, lg, mg, mi, ny, so, mai,
sd, ps, or_IN, my, si, rm, la, lb, tig, tlh, uz-AR, ve, ve-PP, ve-CC, vo, wa,
wal, wo, zgh, to, tpi, wa-RR and ts.

Thanks to xet7 !
2026-11-21 01:33:59 +02:00

65 lines
3.2 KiB
JavaScript

// Import from a service's API (models/lib/apiImportServices.js): the import
// page asks what can be imported, then fetches the chosen one; the JSON it
// gets back is imported like a pasted export, through importBoard. The
// credentials come with each call, are used for that call's requests only,
// and are never stored or logged.
import { Meteor } from 'meteor/meteor';
import { check, Match } from 'meteor/check';
import { DDPRateLimiter } from 'meteor/ddp-rate-limiter';
import { assertImportEnabled } from '/models/lib/importExportSecurity';
import { apiImportRequest } from '/server/lib/apiImportRequest';
import * as planka from '/models/lib/apiImport/planka';
import * as mstodo from '/models/lib/apiImport/mstodo';
import * as onenote from '/models/lib/apiImport/onenote';
import * as teams from '/models/lib/apiImport/teams';
import * as kanbanflow from '/models/lib/apiImport/kanbanflow';
import * as basecamp from '/models/lib/apiImport/basecamp';
import * as googletasks from '/models/lib/apiImport/googletasks';
import * as googlekeep from '/models/lib/apiImport/googlekeep';
const { apiImportService, cleanApiImportCredentials } = require('/models/lib/apiImportServices');
const CLIENTS = { planka, mstodo, onenote, teams, kanbanflow, basecamp, googletasks, googlekeep };
const MAX_ID_LENGTH = 200;
async function prepare(userId, service, credentials) {
if (!userId) throw new Meteor.Error('error-notAuthorized');
// Sandstorm reaches other sites only through Powerbox grants.
if (Meteor.settings?.public?.sandstorm) throw new Meteor.Error('api-import-unavailable', 'Not available in Sandstorm.');
await assertImportEnabled();
if (!apiImportService(service) || !CLIENTS[service]) throw new Meteor.Error('api-import-unknown-service');
try { return cleanApiImportCredentials(service, credentials); }
catch (error) { throw new Meteor.Error('api-import-credentials', error.message); }
}
// Only the message - origin and status - reaches the page.
const failure = error => new Meteor.Error('api-import-failed', String((error && error.message) || error).slice(0, 300));
Meteor.methods({
async apiImportList(service, credentials) {
check(service, String);
check(credentials, Match.Any);
const clean = await prepare(this.userId, service, credentials);
try {
const items = await CLIENTS[service].list(clean, apiImportRequest);
return (Array.isArray(items) ? items : []).slice(0, 1000)
.map(item => ({ id: String(item.id).slice(0, MAX_ID_LENGTH), name: String(item.name || item.id).slice(0, 300) }));
} catch (error) { throw failure(error); }
},
async apiImportFetch(service, credentials, id) {
check(service, String);
check(credentials, Match.Any);
check(id, String);
const clean = await prepare(this.userId, service, credentials);
if (!id || id.length > MAX_ID_LENGTH) throw new Meteor.Error('api-import-failed', 'Choose what to import.');
try {
return await CLIENTS[service].fetch(clean, id, apiImportRequest);
} catch (error) { throw failure(error); }
},
});
// Each call makes requests to another site with the member's credentials.
DDPRateLimiter.addRule({ type: 'method', name: name => ['apiImportList', 'apiImportFetch'].includes(name),
connectionId: () => true }, 10, 60000);