baiduwangpan-cli 1.6.0 → 1.7.0
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/LICENSE +21 -21
- package/README.md +504 -471
- package/bin/bdp.js +1647 -1452
- package/lib/browser-login.js +427 -427
- package/lib/config.js +213 -213
- package/lib/console.js +99 -99
- package/lib/file-type.js +109 -0
- package/lib/group.js +929 -925
- package/lib/http.js +130 -130
- package/lib/index.js +7 -7
- package/lib/mcp.js +287 -0
- package/lib/name-match.js +67 -67
- package/lib/pan.js +1034 -767
- package/lib/partial.js +53 -53
- package/lib/pcs-extra.js +327 -318
- package/lib/table.js +173 -0
- package/package.json +48 -48
- package/scripts/postinstall.js +340 -340
package/lib/name-match.js
CHANGED
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
// ── 文件名匹配(纯函数,无 IO)──────────────────────────
|
|
2
|
-
//
|
|
3
|
-
// 供群文件搜索(lib/group.js 的 gsearch)与网盘搜索(bdp search 集成建议)共用。
|
|
4
|
-
// 所有函数都是同步纯函数:同样的输入永远得到同样的输出,不做任何网络/文件操作。
|
|
5
|
-
//
|
|
6
|
-
// 匹配模式(options.mode):
|
|
7
|
-
// - "all" (默认)空格分词,每个词都必须出现(AND,顺序无关)
|
|
8
|
-
// - "any" 空格分词,任一词出现即可(OR)
|
|
9
|
-
// - "exact" 整名精确相等(大小写不敏感,按 basename 比较,忽略目录前缀)
|
|
10
|
-
// - "regex" pattern 直接作为正则表达式
|
|
11
|
-
// - "glob" pattern 按 shell glob(* 任意串、? 单字符)匹配
|
|
12
|
-
// 单关键词时 all/any 都退化为子串包含(与 group.js 旧行为兼容)。
|
|
13
|
-
|
|
14
|
-
// 正则元字符转义:普通字符串 → 可安全嵌入正则的等价字面量
|
|
15
|
-
function escapeRegExp(s) {
|
|
16
|
-
return String(s).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// shell glob 转正则:* → .*(任意串,含空)、? → .(任意单字符)、
|
|
20
|
-
// 其余字符全部按字面量转义(如 "1.5版" 的 "." 在 glob 中就是普通句点)。
|
|
21
|
-
// 结果整体锚定(^...$),即 glob 必须匹配整个文件名(shell 语义)。
|
|
22
|
-
function globToRegExp(pattern) {
|
|
23
|
-
const escaped = String(pattern).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
24
|
-
const src = escaped.replace(/\\\*/g, ".*").replace(/\\\?/g, ".");
|
|
25
|
-
return new RegExp(`^(?:${src})$`);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// 核心匹配函数。
|
|
29
|
-
// pattern: 用户输入的关键词/模式
|
|
30
|
-
// name: 待匹配的文件名(可为完整路径,exact 模式会自动取 basename)
|
|
31
|
-
// options: { mode, ignoreCase },ignoreCase 默认 true(与 group.js 旧行为一致)
|
|
32
|
-
// 返回布尔值。
|
|
33
|
-
function matchesName(pattern, name, options = {}) {
|
|
34
|
-
const mode = options.mode || "all";
|
|
35
|
-
const ignoreCase = options.ignoreCase !== false;
|
|
36
|
-
const raw = String(pattern);
|
|
37
|
-
const k = ignoreCase ? raw.toLowerCase() : raw;
|
|
38
|
-
const n = String(name || "");
|
|
39
|
-
const nn = ignoreCase ? n.toLowerCase() : n;
|
|
40
|
-
|
|
41
|
-
// regex:pattern 直接编译为正则(非法正则向上抛 SyntaxError,由调用方决定处理)
|
|
42
|
-
if (mode === "regex") {
|
|
43
|
-
return new RegExp(raw, ignoreCase ? "i" : "").test(n);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// glob:经 globToRegExp 转换后整体匹配
|
|
47
|
-
if (mode === "glob") {
|
|
48
|
-
return globToRegExp(raw).test(n);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// exact:整名精确相等。按 basename 比较(忽略 "/dir/" 前缀),
|
|
52
|
-
// 顶层分享 name 形如 "/xxx",子目录文件 name 无前缀,两者统一处理。
|
|
53
|
-
if (mode === "exact") {
|
|
54
|
-
const base = nn.includes("/") ? nn.slice(nn.lastIndexOf("/") + 1) : nn;
|
|
55
|
-
return base === k;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// all / any:空格分词。空关键词(含纯空白)不过滤(匹配一切,兼容旧行为);
|
|
59
|
-
// 单关键词退化为子串包含(兼容旧行为)。
|
|
60
|
-
const words = k.trim().split(/\s+/).filter(Boolean);
|
|
61
|
-
if (words.length === 0) return true;
|
|
62
|
-
if (words.length === 1) return nn.includes(words[0]);
|
|
63
|
-
if (mode === "any") return words.some((w) => nn.includes(w));
|
|
64
|
-
return words.every((w) => nn.includes(w)); // 默认 all:每词都需出现(AND)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
module.exports = { globToRegExp, matchesName, escapeRegExp };
|
|
1
|
+
// ── 文件名匹配(纯函数,无 IO)──────────────────────────
|
|
2
|
+
//
|
|
3
|
+
// 供群文件搜索(lib/group.js 的 gsearch)与网盘搜索(bdp search 集成建议)共用。
|
|
4
|
+
// 所有函数都是同步纯函数:同样的输入永远得到同样的输出,不做任何网络/文件操作。
|
|
5
|
+
//
|
|
6
|
+
// 匹配模式(options.mode):
|
|
7
|
+
// - "all" (默认)空格分词,每个词都必须出现(AND,顺序无关)
|
|
8
|
+
// - "any" 空格分词,任一词出现即可(OR)
|
|
9
|
+
// - "exact" 整名精确相等(大小写不敏感,按 basename 比较,忽略目录前缀)
|
|
10
|
+
// - "regex" pattern 直接作为正则表达式
|
|
11
|
+
// - "glob" pattern 按 shell glob(* 任意串、? 单字符)匹配
|
|
12
|
+
// 单关键词时 all/any 都退化为子串包含(与 group.js 旧行为兼容)。
|
|
13
|
+
|
|
14
|
+
// 正则元字符转义:普通字符串 → 可安全嵌入正则的等价字面量
|
|
15
|
+
function escapeRegExp(s) {
|
|
16
|
+
return String(s).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// shell glob 转正则:* → .*(任意串,含空)、? → .(任意单字符)、
|
|
20
|
+
// 其余字符全部按字面量转义(如 "1.5版" 的 "." 在 glob 中就是普通句点)。
|
|
21
|
+
// 结果整体锚定(^...$),即 glob 必须匹配整个文件名(shell 语义)。
|
|
22
|
+
function globToRegExp(pattern) {
|
|
23
|
+
const escaped = String(pattern).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
24
|
+
const src = escaped.replace(/\\\*/g, ".*").replace(/\\\?/g, ".");
|
|
25
|
+
return new RegExp(`^(?:${src})$`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// 核心匹配函数。
|
|
29
|
+
// pattern: 用户输入的关键词/模式
|
|
30
|
+
// name: 待匹配的文件名(可为完整路径,exact 模式会自动取 basename)
|
|
31
|
+
// options: { mode, ignoreCase },ignoreCase 默认 true(与 group.js 旧行为一致)
|
|
32
|
+
// 返回布尔值。
|
|
33
|
+
function matchesName(pattern, name, options = {}) {
|
|
34
|
+
const mode = options.mode || "all";
|
|
35
|
+
const ignoreCase = options.ignoreCase !== false;
|
|
36
|
+
const raw = String(pattern);
|
|
37
|
+
const k = ignoreCase ? raw.toLowerCase() : raw;
|
|
38
|
+
const n = String(name || "");
|
|
39
|
+
const nn = ignoreCase ? n.toLowerCase() : n;
|
|
40
|
+
|
|
41
|
+
// regex:pattern 直接编译为正则(非法正则向上抛 SyntaxError,由调用方决定处理)
|
|
42
|
+
if (mode === "regex") {
|
|
43
|
+
return new RegExp(raw, ignoreCase ? "i" : "").test(n);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// glob:经 globToRegExp 转换后整体匹配
|
|
47
|
+
if (mode === "glob") {
|
|
48
|
+
return globToRegExp(raw).test(n);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// exact:整名精确相等。按 basename 比较(忽略 "/dir/" 前缀),
|
|
52
|
+
// 顶层分享 name 形如 "/xxx",子目录文件 name 无前缀,两者统一处理。
|
|
53
|
+
if (mode === "exact") {
|
|
54
|
+
const base = nn.includes("/") ? nn.slice(nn.lastIndexOf("/") + 1) : nn;
|
|
55
|
+
return base === k;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// all / any:空格分词。空关键词(含纯空白)不过滤(匹配一切,兼容旧行为);
|
|
59
|
+
// 单关键词退化为子串包含(兼容旧行为)。
|
|
60
|
+
const words = k.trim().split(/\s+/).filter(Boolean);
|
|
61
|
+
if (words.length === 0) return true;
|
|
62
|
+
if (words.length === 1) return nn.includes(words[0]);
|
|
63
|
+
if (mode === "any") return words.some((w) => nn.includes(w));
|
|
64
|
+
return words.every((w) => nn.includes(w)); // 默认 all:每词都需出现(AND)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
module.exports = { globToRegExp, matchesName, escapeRegExp };
|