dsh-qizhoucnc-cam 1.3.7 → 1.3.8
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/client.js +56 -1
- package/freecad_install.js +167 -0
- package/index.js +60 -1
- package/package.json +2 -1
package/client.js
CHANGED
|
@@ -895,6 +895,9 @@ window.__ModuleLoader__.load({
|
|
|
895
895
|
const [showReward, setShowReward] = React.useState(false);
|
|
896
896
|
// 底部设置区(主体零件位移/旋转 + 夹具/毛坯)折叠/展开
|
|
897
897
|
const [setupCollapsed, setSetupCollapsed] = React.useState(false);
|
|
898
|
+
// FreeCAD 自动下载状态(未安装 FreeCAD 时展示进度并触发下载)
|
|
899
|
+
const [fcStatus, setFcStatus] = React.useState(null); // { phase:'idle'|'downloading'|'extracting'|'done'|'error', ... }
|
|
900
|
+
const [fcChecking, setFcChecking] = React.useState(false);
|
|
898
901
|
const panelRef = React.useRef(null);
|
|
899
902
|
const assetFileRef = React.useRef(null); // 隐藏的 <input type=file>,用于原生「打开文件」对话框选择 STEP
|
|
900
903
|
// 可拖拽调节的面板宽度(像素),持久化到 localStorage
|
|
@@ -998,6 +1001,9 @@ window.__ModuleLoader__.load({
|
|
|
998
1001
|
return () => clearInterval(t);
|
|
999
1002
|
}, [loadChangedNc]);
|
|
1000
1003
|
|
|
1004
|
+
// 挂载时查询一次 FreeCAD 状态(未安装时展示下载入口)
|
|
1005
|
+
React.useEffect(() => { checkFcStatus(); }, [checkFcStatus]);
|
|
1006
|
+
|
|
1001
1007
|
const post = React.useCallback((path, body) => fetch(path, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body || {}) }).then((r) => r.json()), []);
|
|
1002
1008
|
|
|
1003
1009
|
const reveal = React.useCallback((filePath) => {
|
|
@@ -1063,6 +1069,28 @@ window.__ModuleLoader__.load({
|
|
|
1063
1069
|
.finally(() => { setBusy(false); setModelLoading(false); });
|
|
1064
1070
|
}, [post]);
|
|
1065
1071
|
|
|
1072
|
+
// 查询 FreeCAD 自动下载/安装状态
|
|
1073
|
+
const checkFcStatus = React.useCallback(() => {
|
|
1074
|
+
fetch('/dsh-cam/freecad').then((r) => r.json()).then((d) => {
|
|
1075
|
+
if (d && d.ok) setFcStatus(d);
|
|
1076
|
+
}).catch(() => {});
|
|
1077
|
+
}, []);
|
|
1078
|
+
// 触发 FreeCAD 自动下载(官方 GitHub Releases 便携版)
|
|
1079
|
+
const startFcDownload = React.useCallback(() => {
|
|
1080
|
+
setFcChecking(true);
|
|
1081
|
+
post('/dsh-cam/freecad', {})
|
|
1082
|
+
.then((d) => { if (d && d.ok) setFcStatus(d); })
|
|
1083
|
+
.catch((e) => setErr(String(e)))
|
|
1084
|
+
.finally(() => setFcChecking(false));
|
|
1085
|
+
}, [post]);
|
|
1086
|
+
// 下载中轮询进度
|
|
1087
|
+
React.useEffect(() => {
|
|
1088
|
+
if (fcStatus && fcStatus.phase === 'downloading') {
|
|
1089
|
+
const t = setInterval(() => { fetch('/dsh-cam/freecad').then((r) => r.json()).then((d) => { if (d && d.ok) setFcStatus(d); }).catch(() => {}); }, 1500);
|
|
1090
|
+
return () => clearInterval(t);
|
|
1091
|
+
}
|
|
1092
|
+
}, [fcStatus && fcStatus.phase]);
|
|
1093
|
+
|
|
1066
1094
|
// 拉取该模型已写入的「识别文件」标注
|
|
1067
1095
|
const loadFeatures = React.useCallback((modelPath) => {
|
|
1068
1096
|
fetch('/dsh-cam/feature?model=' + encodeURIComponent(modelPath))
|
|
@@ -1433,7 +1461,34 @@ window.__ModuleLoader__.load({
|
|
|
1433
1461
|
: h('div', { style: { display: 'flex', flexDirection: 'column', gap: 2, maxHeight: 90, overflow: 'auto' } }, stepItems),
|
|
1434
1462
|
h('div', { style: { display: 'flex', gap: 6, marginTop: 8 } },
|
|
1435
1463
|
h('input', { style: input, value: modelFile, placeholder: '或手动输入 STEP 路径', onChange: (e) => setModelFile(e.target.value), onKeyDown: (e) => { if (e.key === 'Enter') loadModel(modelFile); } }),
|
|
1436
|
-
h('button', { style: btnPrimary, onClick: () => loadModel(modelFile), disabled: busy }, modelLoading ? '加载中…' : '加载模型'))
|
|
1464
|
+
h('button', { style: btnPrimary, onClick: () => loadModel(modelFile), disabled: busy }, modelLoading ? '加载中…' : '加载模型')),
|
|
1465
|
+
// FreeCAD 未安装时的自动下载入口(Windows / Linux 便携版)
|
|
1466
|
+
fcStatus && fcStatus.found === false && fcStatus.phase !== 'downloading' && fcStatus.phase !== 'extracting' && fcStatus.phase !== 'done'
|
|
1467
|
+
? h('div', {
|
|
1468
|
+
style: {
|
|
1469
|
+
display: 'flex', alignItems: 'center', gap: 6, marginTop: 8, padding: '8px 10px', borderRadius: 8,
|
|
1470
|
+
background: 'rgba(245,158,11,0.12)', border: '1px solid rgba(245,158,11,0.4)',
|
|
1471
|
+
},
|
|
1472
|
+
},
|
|
1473
|
+
h('span', { style: { flex: 1, fontSize: 11, color: '#92400e' } },
|
|
1474
|
+
fcStatus.phase === 'error' ? 'FreeCAD 自动下载失败:' + (fcStatus.error || '未知错误') : '未检测到 FreeCAD,加载/生成需要它。'),
|
|
1475
|
+
fcStatus.phase === 'error'
|
|
1476
|
+
? h('button', { style: btnPrimary, onClick: startFcDownload, disabled: fcChecking }, fcChecking ? '准备中…' : '重试下载')
|
|
1477
|
+
: h('button', { style: btnPrimary, onClick: startFcDownload, disabled: fcChecking }, fcChecking ? '准备中…' : '自动下载 FreeCAD'))
|
|
1478
|
+
: null,
|
|
1479
|
+
fcStatus && (fcStatus.phase === 'downloading' || fcStatus.phase === 'extracting')
|
|
1480
|
+
? h('div', {
|
|
1481
|
+
style: { display: 'flex', flexDirection: 'column', gap: 4, marginTop: 8, padding: '8px 10px', borderRadius: 8, background: 'var(--dsw-alias-bg-layer-2, #f3f4f6)', border: '1px solid var(--dsw-alias-border-l1, #e5e7eb)' },
|
|
1482
|
+
},
|
|
1483
|
+
h('div', { style: { fontSize: 11, color: 'var(--dsw-alias-label-primary, #111)' } }, fcStatus.phase === 'downloading' ? '正在下载 FreeCAD 便携版…' : '正在解压 FreeCAD…'),
|
|
1484
|
+
fcStatus.phase === 'downloading' && typeof fcStatus.total === 'number' && fcStatus.total > 0
|
|
1485
|
+
? h('div', { style: { fontSize: 11, color: 'var(--dsw-alias-label-secondary, #6b7280)' } },
|
|
1486
|
+
Math.round(((fcStatus.downloaded || 0) / fcStatus.total) * 100) + '%(' + Math.round((fcStatus.downloaded || 0) / 1024 / 1024) + ' / ' + Math.round(fcStatus.total / 1024 / 1024) + ' MB)')
|
|
1487
|
+
: null)
|
|
1488
|
+
: null,
|
|
1489
|
+
fcStatus && fcStatus.phase === 'done' && fcStatus.bin
|
|
1490
|
+
? h('div', { style: { fontSize: 11, color: '#16a34a', marginTop: 6 } }, '✓ FreeCAD 已就绪:' + basenameOf(fcStatus.bin))
|
|
1491
|
+
: null),
|
|
1437
1492
|
h('div', { style: { display: 'flex', alignItems: 'center', gap: 6, padding: '6px 12px 0' } },
|
|
1438
1493
|
h('button', {
|
|
1439
1494
|
onClick: () => setViewMode('toolpath'),
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// 自动下载 FreeCAD(便携版)到插件数据目录,并定位 freecadcmd 可执行文件。
|
|
2
|
+
// 覆盖:Linux AppImage(解压 --appimage-extract)、Windows 7z(需本机 7z 解压)。
|
|
3
|
+
// macOS 暂不支持自动下载(返回明确提示),当前机器默认路径 /Applications/FreeCAD.app 已可被 resolveFreecadBin 探测。
|
|
4
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
5
|
+
import { existsSync, mkdirSync, writeFileSync, readFileSync, chmodSync, readdirSync, statSync, renameSync } from 'node:fs';
|
|
6
|
+
import { join, basename } from 'node:path';
|
|
7
|
+
import { homedir } from 'node:os';
|
|
8
|
+
|
|
9
|
+
export const FREEACAD_DIR = join(homedir(), '.dsh', 'storages', 'dsh-cam-freecad');
|
|
10
|
+
const STATE_FILE = join(FREEACAD_DIR, 'install-state.json');
|
|
11
|
+
const RELEASES_API = 'https://api.github.com/repos/FreeCAD/FreeCAD/releases/latest';
|
|
12
|
+
|
|
13
|
+
// 各平台可选用的便携资产(Windows 用 7z,Linux 用 AppImage;macOS 暂无便携方案,标记 unsupported)。
|
|
14
|
+
const PLATFORM_ASSETS = {
|
|
15
|
+
'linux-x64': { label: 'Linux x86_64 AppImage', pattern: /FreeCAD_.*-Linux-x86_64\.AppImage$/i, kind: 'appimage' },
|
|
16
|
+
'linux-arm64': { label: 'Linux aarch64 AppImage', pattern: /FreeCAD_.*-Linux-aarch64\.AppImage$/i, kind: 'appimage' },
|
|
17
|
+
'win32-x64': { label: 'Windows x86_64 7z', pattern: /FreeCAD_.*-Windows-x86_64\.7z$/i, kind: '7z' },
|
|
18
|
+
'win32-arm64': { label: 'Windows arm64 7z', pattern: /FreeCAD_.*-Windows-arm64\.7z$/i, kind: '7z' },
|
|
19
|
+
'darwin-arm64':{ label: 'macOS arm64 dmg', pattern: /FreeCAD_.*-macOS-arm64.*\.dmg$/i, kind: 'dmg' },
|
|
20
|
+
'darwin-x64': { label: 'macOS x86_64 dmg', pattern: /FreeCAD_.*-macOS-x86_64.*\.dmg$/i, kind: 'dmg' },
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
function platformKey() {
|
|
24
|
+
const arch = process.arch === 'x64' ? 'x64' : process.arch === 'arm64' ? 'arm64' : process.arch;
|
|
25
|
+
return `${process.platform}-${arch}`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function loadState() {
|
|
29
|
+
try { return JSON.parse(readFileSync(STATE_FILE, 'utf8')) || {}; } catch { return {}; }
|
|
30
|
+
}
|
|
31
|
+
function saveState(s) {
|
|
32
|
+
try { mkdirSync(FREEACAD_DIR, { recursive: true }); writeFileSync(STATE_FILE, JSON.stringify(s, null, 2), 'utf8'); } catch { /* ignore */ }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// 模块级内存态(当前进程内权威),磁盘态用于重启后恢复「已下载/已解压」结果。
|
|
36
|
+
let memoryState = loadState();
|
|
37
|
+
let downloadJob = null; // 正在运行的后台 curl 子进程
|
|
38
|
+
|
|
39
|
+
function setState(patch) {
|
|
40
|
+
memoryState = { ...memoryState, ...patch };
|
|
41
|
+
saveState(memoryState);
|
|
42
|
+
return memoryState;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// 用 curl 拉取 GitHub 最新 release 的资产清单(缓存 10 分钟)。
|
|
46
|
+
let releaseCache = { at: 0, assets: [] };
|
|
47
|
+
function fetchReleaseAssets() {
|
|
48
|
+
if (Date.now() - releaseCache.at < 10 * 60 * 1000 && releaseCache.assets.length) return releaseCache.assets;
|
|
49
|
+
const res = spawnSync('curl', ['-s', '--max-time', '25', '-H', 'Accept: application/vnd.github+json', RELEASES_API], { encoding: 'utf8', timeout: 30000 });
|
|
50
|
+
if (res.status !== 0 || !res.stdout) return [];
|
|
51
|
+
try {
|
|
52
|
+
const data = JSON.parse(res.stdout);
|
|
53
|
+
const assets = (data.assets || []).map((a) => ({ name: a.name, size: a.size, url: a.browser_download_url }));
|
|
54
|
+
releaseCache = { at: Date.now(), assets };
|
|
55
|
+
return assets;
|
|
56
|
+
} catch { return []; }
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// 根据当前平台挑选要下载的资产。
|
|
60
|
+
export function freecadAsset() {
|
|
61
|
+
const key = platformKey();
|
|
62
|
+
const spec = PLATFORM_ASSETS[key];
|
|
63
|
+
if (!spec) return { supported: false, reason: `暂不支持平台 ${key} 的自动下载。` };
|
|
64
|
+
if (spec.kind === 'dmg') return { supported: false, reason: 'macOS 暂不支持自动下载,请手动安装 FreeCAD 或填写 freecadBin 路径。', spec };
|
|
65
|
+
const assets = fetchReleaseAssets();
|
|
66
|
+
const hit = assets.find((a) => spec.pattern.test(a.name));
|
|
67
|
+
if (!hit) return { supported: false, reason: '未能在 FreeCAD 官方 release 中找到匹配当前平台的资产。', spec };
|
|
68
|
+
return { supported: true, spec, asset: hit };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// 扫描便携目录,返回已解压好的 freecadcmd 绝对路径,或 null。
|
|
72
|
+
export function portableFreecadBin() {
|
|
73
|
+
if (!existsSync(FREEACAD_DIR)) return null;
|
|
74
|
+
const want = process.platform === 'win32' ? 'freecadcmd.exe' : 'freecadcmd';
|
|
75
|
+
const stack = [FREEACAD_DIR];
|
|
76
|
+
while (stack.length) {
|
|
77
|
+
const dir = stack.pop();
|
|
78
|
+
let entries;
|
|
79
|
+
try { entries = readdirSync(dir); } catch { continue; }
|
|
80
|
+
for (const name of entries) {
|
|
81
|
+
const p = join(dir, name);
|
|
82
|
+
let st; try { st = statSync(p); } catch { continue; }
|
|
83
|
+
if (st.isDirectory()) { stack.push(p); continue; }
|
|
84
|
+
if (name === want) return p;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// 解压已下载资产,返回 freecadcmd 绝对路径或抛错。
|
|
91
|
+
function extractAsset(dest, kind) {
|
|
92
|
+
if (kind === 'appimage') {
|
|
93
|
+
chmodSync(dest, 0o755);
|
|
94
|
+
// AppImage 需 --appimage-extract 解出 squashfs-root/usr/bin/freecadcmd(无需 FUSE)。
|
|
95
|
+
const res = spawnSync(dest, ['--appimage-extract'], { cwd: FREEACAD_DIR, encoding: 'utf8', timeout: 300_000, maxBuffer: 64 * 1024 * 1024 });
|
|
96
|
+
if (res.status !== 0) throw new Error('AppImage 解压失败:' + (res.stderr || res.stdout || '').slice(-600));
|
|
97
|
+
const bin = join(FREEACAD_DIR, 'squashfs-root', 'usr', 'bin', 'freecadcmd');
|
|
98
|
+
if (!existsSync(bin)) throw new Error('AppImage 解压后未找到 freecadcmd:' + bin);
|
|
99
|
+
return bin;
|
|
100
|
+
}
|
|
101
|
+
if (kind === '7z') {
|
|
102
|
+
// Windows 7z 需本机 7z/7za/7zr;找不到则报错提示安装 7-Zip 或用官方安装包。
|
|
103
|
+
let sevenZip = null;
|
|
104
|
+
for (const cmd of ['7z', '7za', '7zr']) {
|
|
105
|
+
const probe = spawnSync(cmd, [], { timeout: 5000 });
|
|
106
|
+
if (probe.error === undefined || probe.error === null) { sevenZip = cmd; break; }
|
|
107
|
+
}
|
|
108
|
+
if (!sevenZip) {
|
|
109
|
+
throw new Error('解压 FreeCAD 7z 需要本机安装 7-Zip(未找到 7z 命令)。请先安装 7-Zip,或改用官方 installer.exe 安装。');
|
|
110
|
+
}
|
|
111
|
+
const res = spawnSync(sevenZip, ['x', '-y', '-o' + FREEACAD_DIR, dest], { encoding: 'utf8', timeout: 600_000, maxBuffer: 64 * 1024 * 1024 });
|
|
112
|
+
if (res.status !== 0) throw new Error('7z 解压失败:' + (res.stderr || res.stdout || '').slice(-600));
|
|
113
|
+
const bin = portableFreecadBin();
|
|
114
|
+
if (!bin) throw new Error('7z 解压后未找到 freecadcmd.exe');
|
|
115
|
+
return bin;
|
|
116
|
+
}
|
|
117
|
+
throw new Error('不支持的资产类型:' + kind);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// 后台下载(幂等:已在下载/已就绪则直接返回状态)。返回当前状态快照。
|
|
121
|
+
export function ensureFreecadDownload() {
|
|
122
|
+
if (memoryState.bin && existsSync(memoryState.bin)) {
|
|
123
|
+
return { ...memoryState, phase: 'done' };
|
|
124
|
+
}
|
|
125
|
+
if (downloadJob && downloadJob.exitCode === null) {
|
|
126
|
+
return memoryState; // 正在下载
|
|
127
|
+
}
|
|
128
|
+
const { supported, spec, asset, reason } = freecadAsset();
|
|
129
|
+
if (!supported) {
|
|
130
|
+
return setState({ phase: 'error', error: reason });
|
|
131
|
+
}
|
|
132
|
+
mkdirSync(FREEACAD_DIR, { recursive: true });
|
|
133
|
+
const dest = join(FREEACAD_DIR, asset.name);
|
|
134
|
+
setState({ phase: 'downloading', asset: asset.name, url: asset.url, dest, total: asset.size, downloaded: 0, error: null, bin: null });
|
|
135
|
+
const child = spawn('curl', ['-L', '--fail', '--retry', '3', '--retry-delay', '3', '-C', '-', '-o', dest, asset.url], {
|
|
136
|
+
cwd: FREEACAD_DIR, stdio: ['ignore', 'ignore', 'pipe'],
|
|
137
|
+
});
|
|
138
|
+
let errBuf = '';
|
|
139
|
+
child.stderr.on('data', (d) => { errBuf += String(d); });
|
|
140
|
+
child.on('exit', (code) => {
|
|
141
|
+
downloadJob = null;
|
|
142
|
+
if (code !== 0) {
|
|
143
|
+
setState({ phase: 'error', error: '下载失败:' + (errBuf.slice(-400) || ('exit ' + code)) });
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
try {
|
|
147
|
+
setState({ phase: 'extracting' });
|
|
148
|
+
const bin = extractAsset(dest, spec.kind);
|
|
149
|
+
setState({ phase: 'done', bin, downloaded: asset.size });
|
|
150
|
+
} catch (e) {
|
|
151
|
+
setState({ phase: 'error', error: String(e && e.message ? e.message : e) });
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
downloadJob = child;
|
|
155
|
+
return memoryState;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// 下载进度:轮询 dest 文件大小,更新内存/磁盘态。
|
|
159
|
+
export function freecadInstallStatus() {
|
|
160
|
+
if (memoryState.phase === 'downloading' && memoryState.dest) {
|
|
161
|
+
try {
|
|
162
|
+
const st = statSync(memoryState.dest);
|
|
163
|
+
if (st.size !== memoryState.downloaded) setState({ downloaded: st.size });
|
|
164
|
+
} catch { /* file not created yet */ }
|
|
165
|
+
}
|
|
166
|
+
return { ...memoryState, platform: platformKey(), supported: !!PLATFORM_ASSETS[platformKey()] && PLATFORM_ASSETS[platformKey()].kind !== 'dmg' };
|
|
167
|
+
}
|
package/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import { mkdtempSync, readFileSync, writeFileSync, existsSync, mkdirSync, readdi
|
|
|
5
5
|
import { tmpdir, homedir } from 'node:os';
|
|
6
6
|
import { join, dirname, basename, isAbsolute, relative, resolve } from 'node:path';
|
|
7
7
|
import { fileURLToPath } from 'node:url';
|
|
8
|
+
import { ensureFreecadDownload, freecadInstallStatus, portableFreecadBin } from './freecad_install.js';
|
|
8
9
|
|
|
9
10
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
10
11
|
// 默认 FreeCAD 路径(macOS)。其它机器可经插件设置覆盖 freecadBin。
|
|
@@ -82,7 +83,7 @@ function findPython() {
|
|
|
82
83
|
return null;
|
|
83
84
|
}
|
|
84
85
|
|
|
85
|
-
// 解析 FreeCAD 可执行文件路径:优先插件设置 freecadBin
|
|
86
|
+
// 解析 FreeCAD 可执行文件路径:优先插件设置 freecadBin,其次默认路径,再按候选列表探测,最后 PATH / Spotlight 命令探测。
|
|
86
87
|
function resolveFreecadBin(configured) {
|
|
87
88
|
if (typeof configured === 'string' && configured.trim()) {
|
|
88
89
|
if (existsSync(configured.trim())) return configured.trim();
|
|
@@ -92,6 +93,46 @@ function resolveFreecadBin(configured) {
|
|
|
92
93
|
for (const cand of FREECAD_BIN_CANDIDATES) {
|
|
93
94
|
if (existsSync(cand)) return cand;
|
|
94
95
|
}
|
|
96
|
+
// 已自动下载的便携版 FreeCAD(Windows 7z 解压 / Linux AppImage 解压)
|
|
97
|
+
try {
|
|
98
|
+
const portable = portableFreecadBin();
|
|
99
|
+
if (portable && existsSync(portable)) return portable;
|
|
100
|
+
} catch { /* ignore */ }
|
|
101
|
+
// PATH 命令探测(which / where)
|
|
102
|
+
const whichCmd = process.platform === 'win32' ? 'where' : 'which';
|
|
103
|
+
for (const cmd of ['freecadcmd', 'freecad']) {
|
|
104
|
+
try {
|
|
105
|
+
const probe = spawnSync(whichCmd, [cmd], { timeout: 6000, encoding: 'utf8' });
|
|
106
|
+
if (probe.status === 0 && probe.stdout) {
|
|
107
|
+
const first = probe.stdout.split(/\r?\n/).map((s) => s.trim()).filter(Boolean)
|
|
108
|
+
.find((p) => existsSync(p));
|
|
109
|
+
if (first) return first;
|
|
110
|
+
}
|
|
111
|
+
} catch { /* try next */ }
|
|
112
|
+
}
|
|
113
|
+
// macOS Spotlight 全盘索引查找
|
|
114
|
+
if (process.platform === 'darwin') {
|
|
115
|
+
try {
|
|
116
|
+
const probe = spawnSync('mdfind', ['(kMDItemFSName == "freecadcmd") || (kMDItemFSName == "freecad")'], { timeout: 10000, encoding: 'utf8' });
|
|
117
|
+
if (probe.status === 0 && probe.stdout) {
|
|
118
|
+
const first = probe.stdout.split(/\r?\n/).map((s) => s.trim()).filter(Boolean)
|
|
119
|
+
.find((p) => existsSync(p) && /freecad(cmd)?$/i.test(p));
|
|
120
|
+
if (first) return first;
|
|
121
|
+
}
|
|
122
|
+
} catch { /* ignore */ }
|
|
123
|
+
}
|
|
124
|
+
// Windows:扫描常见安装目录 Program Files 下的 FreeCAD* 版本目录
|
|
125
|
+
if (process.platform === 'win32') {
|
|
126
|
+
for (const root of ['C:\\Program Files', 'C:\\Program Files (x86)']) {
|
|
127
|
+
try {
|
|
128
|
+
for (const entry of readdirSync(root)) {
|
|
129
|
+
if (!/^freecad/i.test(entry)) continue;
|
|
130
|
+
const bin = join(root, entry, 'bin', 'freecadcmd.exe');
|
|
131
|
+
if (existsSync(bin)) return bin;
|
|
132
|
+
}
|
|
133
|
+
} catch { /* ignore */ }
|
|
134
|
+
}
|
|
135
|
+
}
|
|
95
136
|
return null;
|
|
96
137
|
}
|
|
97
138
|
|
|
@@ -773,6 +814,24 @@ export function apply(ctx, config = {}) {
|
|
|
773
814
|
}
|
|
774
815
|
},
|
|
775
816
|
}));
|
|
817
|
+
|
|
818
|
+
// FreeCAD 自动下载状态(供客户端展示进度 / 触发下载)
|
|
819
|
+
routeDisposers.push(server.register({
|
|
820
|
+
kind: 'prefix',
|
|
821
|
+
path: '/dsh-cam/freecad',
|
|
822
|
+
handler: async (req, res) => {
|
|
823
|
+
try {
|
|
824
|
+
if (req.method === 'POST') {
|
|
825
|
+
const st = ensureFreecadDownload();
|
|
826
|
+
send(res, { ok: true, found: !!resolveFreecadBin(freecadBin), ...st });
|
|
827
|
+
return;
|
|
828
|
+
}
|
|
829
|
+
send(res, { ok: true, found: !!resolveFreecadBin(freecadBin), ...freecadInstallStatus() });
|
|
830
|
+
} catch (e) {
|
|
831
|
+
send(res, { ok: false, error: String(e && e.message ? e.message : e) }, 400);
|
|
832
|
+
}
|
|
833
|
+
},
|
|
834
|
+
}));
|
|
776
835
|
};
|
|
777
836
|
ensureRoutes();
|
|
778
837
|
const retry = setInterval(() => { if (routeDisposers.length === 0) ensureRoutes(); }, 100);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-qizhoucnc-cam",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.8",
|
|
4
4
|
"description": "CNC program (NC/CNC/G-code) toolpath recognition, 3D toolpath + 3D STEP model viewport (face/edge machining-position annotation), and a large editing view with quote-to-composer, for DeepSeek Harness (DSH). Made by Chengdu Qizhou Machinery Technology Co., Ltd., for research and study only.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"files": [
|
|
34
34
|
"index.js",
|
|
35
35
|
"client.js",
|
|
36
|
+
"freecad_install.js",
|
|
36
37
|
"cam_script.py",
|
|
37
38
|
"toolpath_render.py",
|
|
38
39
|
"cordis.patch.yml",
|