@xiaofanzhao/dsh-plugin-knowledge-base 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -1
- package/lib/preview.mjs +30 -21
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -336,7 +336,21 @@ $env:KB_TEST_XLSX = "C:\path\to\any.xlsx"
|
|
|
336
336
|
|
|
337
337
|
- 老版 Office(`.doc/.ppt/.xls`)能看原版式,但不抽正文,搜不到里面的字
|
|
338
338
|
- 扫描件 PDF / 纯图片没有文字层,搜不到内容
|
|
339
|
-
-
|
|
339
|
+
- **原版式转换受 DSH 的 office-kit 限制**,默认 `maxInputBytes = 50 MB`。超过时不是卡住,而是立刻提示原因(可切「文字版」或「下载」)。
|
|
340
|
+
想放宽:在 profile 的 `cordis.patch.yml` 里给 office-kit 加一段配置(`maxInputBytes` 必须 ≤ `maxSourceBytes`):
|
|
341
|
+
|
|
342
|
+
```yaml
|
|
343
|
+
- id: office-kit
|
|
344
|
+
name: "@deepseek-ai/dsh-office-kit"
|
|
345
|
+
config:
|
|
346
|
+
maxInputBytes: 209715200
|
|
347
|
+
maxSourceBytes: 314572800
|
|
348
|
+
maxOutputBytes: 314572800
|
|
349
|
+
timeoutMs: 300000
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
本机没装原生 LibreOffice 时走的是 **WASM 引擎**:57 MB 的 PPT 实测转换约 **58 秒**,再大只会更慢,所以放宽上限主要适合"偶尔一个大文件"。
|
|
353
|
+
- 单次渲图最多 200 页
|
|
340
354
|
- 桌面端不允许插件页面开新窗口,所以「大屏」是应用内全屏,不是独立窗口
|
|
341
355
|
|
|
342
356
|
## License
|
package/lib/preview.mjs
CHANGED
|
@@ -12,10 +12,12 @@ export const OFFICE_EXTENSIONS = new Set(['doc', 'docx', 'ppt', 'pptx', 'xls', '
|
|
|
12
12
|
export const IMAGE_EXTENSIONS = new Set(['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp', 'svg']);
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* officeKit
|
|
16
|
-
*
|
|
15
|
+
* officeKit(DSH 的 @deepseek-ai/dsh-office-kit)默认的输入上限是 50 MB,
|
|
16
|
+
* 可以通过 profile 里 office-kit 行的 config.maxInputBytes 调大。
|
|
17
|
+
* 这里只用来把英文报错翻译成人话,不再自己做硬性拦截 ——
|
|
18
|
+
* 否则宿主把上限调大后,插件这边反而先挡住了。
|
|
17
19
|
*/
|
|
18
|
-
export const
|
|
20
|
+
export const OFFICE_DEFAULT_MAX_INPUT_BYTES = 50 * 1024 * 1024;
|
|
19
21
|
|
|
20
22
|
/** 逐页预览首屏先渲这么多页,剩下的后台继续 —— 大文档不用等全部渲染完。 */
|
|
21
23
|
const FIRST_PAGES = 6;
|
|
@@ -70,30 +72,37 @@ export function createPreviewer({ store, getOfficeKit, logger }) {
|
|
|
70
72
|
const hit = cached(node, sourcePath);
|
|
71
73
|
if (hit) return hit;
|
|
72
74
|
|
|
73
|
-
// officeKit 的转换有输入上限(超过就报 "exceeds maxInputBytes"),
|
|
74
|
-
// 提前判掉,省得界面在那儿转圈转到超时。
|
|
75
|
-
const sourceStat = fs.statSync(sourcePath);
|
|
76
|
-
if (sourceStat.size > OFFICE_MAX_INPUT_BYTES) {
|
|
77
|
-
throw unavailable(`文件 ${(sourceStat.size / 1048576).toFixed(1)} MB,超过 Office 转换上限 `
|
|
78
|
-
+ `${Math.round(OFFICE_MAX_INPUT_BYTES / 1048576)} MB,生成不了原版式预览;可以切「文字版」或「下载」原件`);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
75
|
const running = jobs.get(node.id);
|
|
82
76
|
if (running) return running;
|
|
83
77
|
|
|
84
78
|
const job = (async () => {
|
|
85
79
|
const stat = fs.statSync(sourcePath);
|
|
86
80
|
const version = `${stat.size}-${Math.round(stat.mtimeMs)}`;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
81
|
+
let result;
|
|
82
|
+
try {
|
|
83
|
+
result = await kit.convert({
|
|
84
|
+
extension: node.ext,
|
|
85
|
+
priority,
|
|
86
|
+
source: {
|
|
87
|
+
key: `${node.id}:${version}`,
|
|
88
|
+
version,
|
|
89
|
+
bytes: stat.size,
|
|
90
|
+
read: async () => ({ bytes: new Uint8Array(await fs.promises.readFile(sourcePath)), version }),
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
} catch (error) {
|
|
94
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
95
|
+
if (/maxInputBytes/i.test(message)) {
|
|
96
|
+
throw unavailable(`文件 ${(stat.size / 1048576).toFixed(1)} MB,超过这台机器 Office 转换的输入上限`
|
|
97
|
+
+ `(office-kit 默认 ${Math.round(OFFICE_DEFAULT_MAX_INPUT_BYTES / 1048576)} MB,可在 profile 配置里调大 `
|
|
98
|
+
+ 'maxInputBytes);也可以把文件拆小,或先另存为 PDF 再上传。');
|
|
99
|
+
}
|
|
100
|
+
if (/timeout|deadline/i.test(message)) {
|
|
101
|
+
throw unavailable(`这台机器转换超时(${Math.round(stat.size / 1048576)} MB 的文件太大或太复杂);`
|
|
102
|
+
+ '可以调大 office-kit 的 timeoutMs,或先另存为 PDF 再上传。');
|
|
103
|
+
}
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
97
106
|
const pdf = result?.pdf ?? result;
|
|
98
107
|
if (!pdf || typeof pdf.length !== 'number' || !pdf.length) {
|
|
99
108
|
throw new Error('转换没有返回 PDF 内容');
|