Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.8.0

### Removed

- **`init` 命令**:移除 `larkDocx2md init` 凭证初始化入口;`download` / `get-titles` 不再读取已存储凭证(macOS Keychain 或 `~/.lark-docx2md/auth.json`),仅支持命令行参数与环境变量

## 0.7.0

### Features
Expand Down
25 changes: 1 addition & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,7 @@ export LARK_DOCX2MD_APP_SECRET=<APP_SECRET>
npx -y lark-docx2md@latest download --url <url>
```

或使用 `init` 命令一键配置并持久化凭证(macOS 存入系统 Keychain,其他系统存入 `~/.lark-docx2md/auth.json`):

```bash
npx -y lark-docx2md@latest init
```

完成后即可直接使用 `download` / `get-titles`,无需每次传入 `--app-id` / `--app-secret` 或设置环境变量。

> **凭证优先级**:命令行参数 > 已存储凭证(macOS: Keychain;其他: auth.json)> 环境变量
> **凭证优先级**:命令行参数 > 环境变量

## 参数

Expand Down Expand Up @@ -71,21 +63,6 @@ npx -y lark-docx2md@latest init
> - `--max-output-lines`:仅在未指定 `--filter-title` / `--filter-title-block-id` 时生效;纯 Markdown 阶段先检查一次,图片、画板、表格等解析完成后再检查一次。超过限制时直接报错,提示先用 `get-titles` 获取标题,再补充标题过滤参数重试。
> - **命中深层标题时自动注入父级标题(仅 heading 块本身)**:两个过滤参数均会按文档顺序补齐包含路径上的顶层→该标题的所有祖先标题,以保留章节层级上下文;不会引入旁支兄弟或伪造跳级。

## 子命令:`init`

交互式配置飞书应用凭证。通过飞书一键应用流程注册并验证凭证,macOS 保存至系统 Keychain,其他系统保存至 `~/.lark-docx2md/auth.json`。

```bash
npx -y lark-docx2md@latest init
```

| 参数 | 说明 | 默认值 |
|------|------|--------|
| `--no-probe` | 跳过凭证验证步骤 | `false` |
| `--timeout <ms>` | 请求超时(毫秒) | `30000` |

已配置时再次运行可替换或移除现有凭证。

## 子命令:`get-titles`

列出 docx/wiki 文档全部标题(不支持 sheets),配合 `--filter-title-block-id` 使用可避开同名歧义。
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lark-docx2md",
"version": "0.7.0",
"version": "0.8.0",
"description": "Convert Lark/Feishu documents to Markdown",
"type": "module",
"main": "./dist/converter.js",
Expand Down
10 changes: 0 additions & 10 deletions src/cli/program.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Command } from 'commander';
import { handleDownloadCommand, handleGetTitlesCommand } from './handlers.js';
import { handleInitCommand, type InitRawOptions } from './init-handler.js';
import type { DownloadRawOptions, GetTitlesRawOptions } from './options.js';

export function createProgram (): Command {
Expand Down Expand Up @@ -43,15 +42,6 @@ export function createProgram (): Command {
handleGetTitlesCommand(positionalUrl, opts, message => program.error(message))
));

program
.command('init')
.description('管理应用凭证:新增、替换或移除已存储的飞书应用凭证')
.option('--no-probe', '注册后跳过 tenant_access_token 验证')
.option('--timeout <ms>', '每次请求超时时间(毫秒,默认 30000)')
.action((opts: InitRawOptions) => (
handleInitCommand(opts, message => program.error(message))
));

return program;
}

Expand Down
24 changes: 4 additions & 20 deletions src/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import * as lark from '@larksuiteoapi/node-sdk';
import { LoggerLevel } from '@larksuiteoapi/node-sdk';
import * as fs from 'node:fs';
import * as path from 'node:path';
import { platform } from 'node:os';
import { getStoredCredentials } from './auth-store.js';
import type { DocInfo, DocxBlock, WhiteboardNode } from './types.js';

const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
Expand All @@ -12,29 +10,15 @@ const RATE_LIMIT_RETRY_DELAY = 500;

/**
* 创建飞书 API 客户端。
* 凭证优先级:传入参数(CLI)> 已存储凭证(macOS: Keychain; 其他: auth.json 明文)> 环境变量。
* 凭证优先级:传入参数(CLI)> 环境变量。
*/
export async function createClient (cliAppId?: string, cliAppSecret?: string, loggerLevel: LoggerLevel = LoggerLevel.warn) {
let appId = cliAppId;
let appSecret = cliAppSecret;
const appId = cliAppId || process.env.LARK_DOCX2MD_APP_ID;
const appSecret = cliAppSecret || process.env.LARK_DOCX2MD_APP_SECRET;

if (!appId || !appSecret) {
const stored = await getStoredCredentials();
appId = appId || stored.appId;
appSecret = appSecret || stored.appSecret;
}

if (!appId || !appSecret) {
appId = appId || process.env.LARK_DOCX2MD_APP_ID;
appSecret = appSecret || process.env.LARK_DOCX2MD_APP_SECRET;
}

if (!appId || !appSecret) {
const initHint = platform() === 'darwin'
? ', run "lark-docx2md init" to store in macOS Keychain,'
: ', run "lark-docx2md init" to store in auth.json,';
throw new Error(
`Missing credentials: pass --app-id/--app-secret${initHint} or set LARK_DOCX2MD_APP_ID/LARK_DOCX2MD_APP_SECRET`,
'Missing credentials: pass --app-id/--app-secret or set LARK_DOCX2MD_APP_ID/LARK_DOCX2MD_APP_SECRET',
);
}

Expand Down
Loading