mirror of
https://github.com/wekan/wekan.git
synced 2026-11-20 21:45:01 -05:00
Decided on 2026-10-14. On the import page each of the six asks for what its service needs - a self-hosted Planka its address, username and password; the others an access token (Basecamp also its account id) - lists what that account can import, and fetches the chosen board, list or project. The credentials go with each call and are used for that call's requests only; they are never stored or logged, and the page clears secret fields once a fetch has used them. The fetched JSON fills the import text box and the import goes on as for a pasted export: the service's parser (models/lib/<key>ApiFormat.js) into the generalized importer, with the members step and the loss report. The same JSON can be pasted, or posted to POST /api/boards/import/<key>. - server/apiImport.js: apiImportList and apiImportFetch, signed in only, off with the Admin Panel's import switch, not in Sandstorm, rate limited; credentials checked against the service's own fields (models/lib/apiImportServices.js). - server/lib/apiImportRequest.js: every request through the SSRF guard - pinned address, no redirects, bounded in time and size - so a Planka address cannot point the server at its own network; an administrator can allow such a host with API_IMPORT_ALLOWED_PRIVATE_HOSTS. An error names only the origin and the status. - models/lib/apiImport/<key>.js: each service's client, plain Node with the request injected, paging bounded and the token only in a header. - Each has a docs page under docs/Features/ImportExport/, listed in the coverage index and External-Tools.md. Tests: tests/<key>ApiImport.test.cjs (client with a fake request, every parsed field, wrong shapes), tests/apiImport.test.cjs (credentials, the gate, the wiring, the shapes refused), api-import.e2e.js (the form for every service, fetched JSON imported through the page, refusals incl. a private address). Live tests, read only, run from build.sh / build.bat -> Tests -> Live tests with your own accounts (releases/live-tests/README.md); they were not run here. New strings translated in all locales. Also: the release risk baseline allows the services' API addresses, and the guards that count import creators, list the import sources and pin the platform fetch() calls know the new ones. Thanks to xet7 !
135 lines
6.2 KiB
JavaScript
135 lines
6.2 KiB
JavaScript
// Google Keep's notes, as models/lib/apiImport/googlekeep.js fetches them
|
|
// from the Keep API, read into WeKan's normalized board (the shape
|
|
// models/lib/externalParsers.js parsers return). Plain JavaScript without
|
|
// Meteor, so tests/googlekeepApiImport.test.cjs runs it in Node.
|
|
//
|
|
// { googlekeep: true, notes: [note] } (or the API's own { notes: [...] })
|
|
// note: { name: 'notes/...', createTime, updateTime, trashTime, trashed,
|
|
// title, body: { text: { text } }
|
|
// | { list: { listItems: [item] } },
|
|
// permissions: [{ name, email, role }], attachments: [{ name, mimeType: [] }] }
|
|
// item: { text: { text }, checked, childListItems: [item] }
|
|
//
|
|
// A note maps to:
|
|
// a text note -> a card in the list "Notes", the text as description
|
|
// a checklist note -> a card in the list "Lists", its items as the
|
|
// checklist "Items"; WeKan checklists are flat, so a
|
|
// child item follows its parent prefixed "↳ "
|
|
// title -> the card title; an untitled note takes its first
|
|
// line (at most 80 characters)
|
|
// name -> the source reference
|
|
// createTime -> the card's creation date
|
|
// Keep has no boards, lists, labels or due dates in its API: everything goes
|
|
// to one board "Google Keep", swimlane Default. Reported: trashed notes (not
|
|
// imported), attachments (not downloaded), sharing with other people.
|
|
|
|
export const MAX_GOOGLE_KEEP_NOTES = 20000;
|
|
export const MAX_GOOGLE_KEEP_TITLE = 80;
|
|
const NOTES = 'Notes';
|
|
const LISTS = 'Lists';
|
|
const CHECKLIST = 'Items';
|
|
const CHILD_MARK = '↳ ';
|
|
const DEFAULT_SWIMLANE = 'Default';
|
|
const MAX_DEPTH = 8;
|
|
|
|
const isObject = value => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
const text = value => (typeof value === 'string' ? value : '');
|
|
const contentText = content => (isObject(content) ? text(content.text) : '');
|
|
|
|
function readInput(input) {
|
|
if (typeof input === 'string') {
|
|
try { return JSON.parse(input); } catch (error) { throw new Error('Google Keep data is not valid JSON'); }
|
|
}
|
|
return input;
|
|
}
|
|
|
|
function isoDate(value) {
|
|
if (!value) return null;
|
|
const date = new Date(value);
|
|
return Number.isNaN(date.getTime()) ? undefined : date.toISOString();
|
|
}
|
|
|
|
// The first non-empty line, cut to the title length.
|
|
function firstLine(value) {
|
|
const line = text(value).split(/\r?\n/).map(part => part.trim()).find(Boolean) || '';
|
|
return line.length > MAX_GOOGLE_KEEP_TITLE ? `${line.slice(0, MAX_GOOGLE_KEEP_TITLE - 1)}…` : line;
|
|
}
|
|
|
|
function flattenItems(items, depth, out) {
|
|
for (const item of Array.isArray(items) ? items : []) {
|
|
if (!isObject(item)) continue;
|
|
const title = contentText(item.text).trim();
|
|
if (title) out.push({ title: `${CHILD_MARK.repeat(depth)}${title}`, done: item.checked === true });
|
|
if (depth < MAX_DEPTH) flattenItems(item.childListItems, depth + 1, out);
|
|
}
|
|
return out;
|
|
}
|
|
|
|
export function parseGoogleKeepApi(input) {
|
|
const data = readInput(input);
|
|
if (!isObject(data)) throw new Error('Google Keep data must be a JSON object');
|
|
if (!Array.isArray(data.notes)) throw new Error('Google Keep data needs a notes array');
|
|
if (data.notes.length > MAX_GOOGLE_KEEP_NOTES) throw new Error(`Google Keep data has more than ${MAX_GOOGLE_KEEP_NOTES} notes`);
|
|
|
|
const unsupported = [];
|
|
const tasks = [];
|
|
let trashed = 0;
|
|
data.notes.forEach((note, index) => {
|
|
const at = `/notes/${index}`;
|
|
if (!isObject(note)) { unsupported.push({ path: at, reason: 'a Google Keep note that is not an object is not imported' }); return; }
|
|
if (note.trashed === true || note.trashTime) { trashed += 1; return; }
|
|
const body = isObject(note.body) ? note.body : {};
|
|
const isList = isObject(body.list);
|
|
const task = {
|
|
title: '',
|
|
description: '',
|
|
column_name: isList ? LISTS : NOTES,
|
|
swimlane_name: DEFAULT_SWIMLANE,
|
|
tags: [],
|
|
};
|
|
if (isList) {
|
|
const items = flattenItems(body.list.listItems, 0, []);
|
|
if (items.length) task.checklists = [{ title: CHECKLIST, items }];
|
|
task.title = text(note.title).trim() || (items.length ? firstLine(items[0].title) : '');
|
|
} else {
|
|
task.description = contentText(body.text);
|
|
task.title = text(note.title).trim() || firstLine(task.description);
|
|
if (note.body !== undefined && !isObject(body.text)) {
|
|
unsupported.push({ path: `${at}/body`, reason: 'a Google Keep note body that is neither text nor a list is not imported' });
|
|
}
|
|
}
|
|
if (!task.title) task.title = 'Untitled note';
|
|
if (text(note.name)) task.ref = text(note.name);
|
|
const created = isoDate(note.createTime);
|
|
if (created) task.date_creation = created;
|
|
else if (created === undefined) unsupported.push({ path: `${at}/createTime`, reason: `Google Keep createTime "${text(note.createTime)}" is not a date` });
|
|
|
|
const attachments = (Array.isArray(note.attachments) ? note.attachments : []).filter(isObject);
|
|
if (attachments.length) {
|
|
const types = [...new Set(attachments.flatMap(a => (Array.isArray(a.mimeType) ? a.mimeType : [])).filter(t => typeof t === 'string'))];
|
|
unsupported.push({ path: `${at}/attachments`,
|
|
reason: `"${task.title}" has ${attachments.length} attachment(s)${types.length ? ` (${types.join(', ')})` : ''}; Google Keep attachments are not downloaded` });
|
|
}
|
|
// The owner is always listed; anyone else means the note is shared.
|
|
const shared = (Array.isArray(note.permissions) ? note.permissions : [])
|
|
.filter(p => isObject(p) && p.role !== 'OWNER' && p.deleted !== true);
|
|
if (shared.length) {
|
|
unsupported.push({ path: `${at}/permissions`,
|
|
reason: `"${task.title}" is shared with ${shared.length} other(s) in Google Keep; sharing is not imported, add them as board members` });
|
|
}
|
|
tasks.push(task);
|
|
});
|
|
if (trashed) unsupported.push({ path: '/notes', reason: `${trashed} trashed Google Keep note(s) are not imported` });
|
|
|
|
const columns = [NOTES, LISTS].filter(name => tasks.some(task => task.column_name === name));
|
|
if (!columns.length) columns.push(NOTES);
|
|
return {
|
|
board: { name: 'Google Keep' },
|
|
columns: columns.map(title => ({ title })),
|
|
swimlanes: [{ name: DEFAULT_SWIMLANE }],
|
|
tasks,
|
|
warnings: [],
|
|
unsupported,
|
|
};
|
|
}
|