mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
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 !
40 lines
1.8 KiB
JavaScript
40 lines
1.8 KiB
JavaScript
// Microsoft Graph for the import clients (OneNote, Teams): the Authorization
|
|
// header of the member's access token, and every page of a list. A next link
|
|
// that leaves Graph would take the token with it, so it is refused. Plain
|
|
// Node; `request` is passed in (models/lib/apiImportServices.js).
|
|
|
|
export const GRAPH = 'https://graph.microsoft.com/v1.0';
|
|
const GRAPH_HOST = 'graph.microsoft.com';
|
|
|
|
export function graphHeaders(credentials, accept = 'application/json') {
|
|
const token = credentials && typeof credentials.token === 'string' ? credentials.token.trim() : '';
|
|
if (!token) throw new Error('token is required');
|
|
return { Authorization: `Bearer ${token}`, Accept: accept };
|
|
}
|
|
|
|
export function graphNext(link) {
|
|
let url;
|
|
try { url = new URL(link); } catch (error) { throw new Error('Microsoft Graph sent a next page link that is not a URL'); }
|
|
if (url.protocol !== 'https:' || url.hostname !== GRAPH_HOST || url.username || url.password) {
|
|
throw new Error('Microsoft Graph sent a next page link to another host');
|
|
}
|
|
return url.href;
|
|
}
|
|
|
|
// Every item of a Graph list, following @odata.nextLink; `state.pages`
|
|
// counts the requests against `max`.
|
|
export async function graphAll(url, headers, request, state, { what, max, maxItems }) {
|
|
const items = [];
|
|
let next = url;
|
|
while (next) {
|
|
state.pages += 1;
|
|
if (state.pages > max) throw new Error(`more than ${max} pages of ${what}`);
|
|
const page = await request(next, { method: 'GET', headers });
|
|
if (!page || typeof page !== 'object' || !Array.isArray(page.value)) throw new Error(`Microsoft Graph did not answer with a list of ${what}`);
|
|
items.push(...page.value);
|
|
if (maxItems && items.length > maxItems) throw new Error(`more than ${maxItems} ${what}`);
|
|
next = page['@odata.nextLink'] ? graphNext(page['@odata.nextLink']) : null;
|
|
}
|
|
return items;
|
|
}
|