mirror of
https://github.com/jackwener/OpenCLI.git
synced 2026-09-14 18:25:42 +08:00
2aee4caa10
* feat(mubu): add mubu (mubu.com) adapter with 5 commands Commands: doc, docs, notes, recent, search. - Uses COOKIE strategy; API calls via in-page XHR with Jwt-Token from localStorage (matches the web app's own mechanism). - Renders node trees to Markdown (default) or plain text; supports tables, tasks, images, emoji, mentions, strikethrough, underline, and nested structures. - notes supports flexible time ranges: single day, month, year, or custom --from/--to spans, plus a --list overview mode. - search returns full-text matches with hit count and snippets for both folders and documents. * fix(manifest): register mubu commands in runtime manifest --------- Co-authored-by: jackwener <jakevingoo@gmail.com>
41 lines
1.3 KiB
JavaScript
41 lines
1.3 KiB
JavaScript
import { cli, Strategy } from '@jackwener/opencli/registry';
|
||
import { ArgumentError } from '@jackwener/opencli/errors';
|
||
import { mubuPost, nodesToMarkdown, nodesToText } from './utils.js';
|
||
|
||
cli({
|
||
site: 'mubu',
|
||
name: 'doc',
|
||
description: '读取幕布文档内容(默认输出 Markdown,可用 --output text 输出纯文本)',
|
||
domain: 'mubu.com',
|
||
strategy: Strategy.COOKIE,
|
||
defaultFormat: 'plain',
|
||
args: [
|
||
{ name: 'id', positional: true, required: true, help: '文档 ID' },
|
||
{ name: 'output', default: 'md', help: '输出格式:md(默认,缩进列表 Markdown,适合导入 Obsidian)或 text(纯文本,适合终端阅读)' },
|
||
],
|
||
columns: ['content'],
|
||
func: async (page, kwargs) => {
|
||
const docId = kwargs.id;
|
||
const format = kwargs.output;
|
||
if (format !== 'md' && format !== 'text') {
|
||
throw new ArgumentError(`--output 只接受 md 或 text,收到:${format}`);
|
||
}
|
||
|
||
await page.goto('https://mubu.com/app');
|
||
|
||
const data = await mubuPost(page, '/document/edit/get', { docId });
|
||
|
||
let nodes = [];
|
||
try {
|
||
const def = JSON.parse(data.definition);
|
||
nodes = def.nodes ?? [];
|
||
} catch {
|
||
return [{ content: data.name }];
|
||
}
|
||
|
||
const output = format === 'md' ? nodesToMarkdown(nodes) : nodesToText(nodes);
|
||
|
||
return [{ content: output }];
|
||
},
|
||
});
|