@zaofan/dsh-qqbot 1.6.0 → 1.6.2

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.
@@ -1,53 +0,0 @@
1
- /**
2
- * 路径规范化(2026-10-02,修 issue #7:手机/POSIX 环境下 cwd 写成反斜杠相对路径 ⇒ 会话创建必失败)
3
- *
4
- * 背景:Android(POSIX) 上 `\\` 不是分隔符,配成 `storage\\emulated\\0\\大肥鱼` 后宿主按字面路径建会话必失败,
5
- * 还会在 workspaces 下生成畸形目录;而失败被 inbound 静默吞掉,用户侧只看到"机器人连上却不说话"。
6
- *
7
- * 规则:
8
- * 1) 反斜杠 → 正斜杠(Windows 用户手写配置时最常见的错)
9
- * 2) 非 win32 平台遇到 Windows 盘符(C:…)→ 明确拒绝(返回空串),不交给 resolve 造幽灵目录
10
- * 3) 相对路径 → 用 path.resolve 落到绝对路径(而不是靠"补一个斜杠")
11
- * 4) 全空白/空串 → 原样返回(由调用方决定默认值)
12
- */
13
- import { isAbsolute, resolve, sep } from 'node:path';
14
- /** 是否 Windows 盘符开头(C:\ / C:/) */
15
- function hasDriveLetter(p) {
16
- return /^[A-Za-z]:[\\/]/.test(p);
17
- }
18
- export function normalizeUserPath(input, opts) {
19
- const raw = String(input ?? '').trim();
20
- if (!raw)
21
- return '';
22
- // 1) 统一分隔符
23
- let p = raw.replace(/\\/g, '/');
24
- // 2) 非 Windows 平台上的盘符路径 → 拒绝(返回空串,让调用方走默认值并告警)
25
- if (process.platform !== 'win32' && hasDriveLetter(p))
26
- return '';
27
- // 3) 相对 → 绝对
28
- if (!isAbsolute(p)) {
29
- const base = opts?.base && isAbsolute(opts.base) ? opts.base : process.cwd();
30
- p = resolve(base, p);
31
- }
32
- // 4) 非 Windows 下把分隔符统一为 '/'(path.resolve 在 POSIX 下本就如此,这里只防御)
33
- if (sep === '/')
34
- p = p.replace(/\\/g, '/');
35
- return p;
36
- }
37
- /** 该路径在本机是否可用(存在 + 可写);不可用时返回原因,可用返回 '' */
38
- export function pathProblem(p) {
39
- if (!p)
40
- return '路径为空';
41
- try {
42
- // eslint-disable-next-line @typescript-eslint/no-var-requires
43
- const fs = require('node:fs');
44
- if (!fs.existsSync(p))
45
- return '目录不存在';
46
- fs.accessSync(p, fs.constants.W_OK);
47
- return '';
48
- }
49
- catch (e) {
50
- return e instanceof Error ? e.message : String(e);
51
- }
52
- }
53
- //# sourceMappingURL=path-utils.js.map