@wu529778790/open-im 0.2.0 → 0.2.1
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.
|
@@ -142,11 +142,38 @@ export class SessionManager {
|
|
|
142
142
|
this.save();
|
|
143
143
|
}
|
|
144
144
|
async resolveAndValidate(baseDir, targetDir) {
|
|
145
|
-
|
|
145
|
+
let resolved;
|
|
146
|
+
// 处理 Windows 驱动器路径 (如 d:, d:/path, d:\path)
|
|
147
|
+
const drivePathMatch = targetDir.match(/^([a-zA-Z]):(.*)$/);
|
|
148
|
+
if (drivePathMatch) {
|
|
149
|
+
const [, drive, rest] = drivePathMatch;
|
|
150
|
+
// 如果 rest 为空或以 \ 或 / 开头,则是驱动器根目录的绝对路径
|
|
151
|
+
// 如果 rest 不为空且不以 \ 或 / 开头,则是驱动器当前目录的相对路径
|
|
152
|
+
if (rest === '' || rest.startsWith('/') || rest.startsWith('\\')) {
|
|
153
|
+
resolved = `${drive}:${rest}`;
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
// 需要获取该驱动器的当前目录,这里简化处理,当作绝对路径
|
|
157
|
+
resolved = `${drive}:${rest}`;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
else if (targetDir === '~' || targetDir.startsWith('~/')) {
|
|
161
|
+
// 处理家目录
|
|
162
|
+
const home = process.env.USERPROFILE || process.env.HOME || '';
|
|
163
|
+
resolved = join(home, targetDir.slice(1));
|
|
164
|
+
}
|
|
165
|
+
else if (targetDir.startsWith('/') || (targetDir.length >= 3 && targetDir[1] === ':' && (targetDir[2] === '\\' || targetDir[2] === '/'))) {
|
|
166
|
+
// 绝对路径
|
|
167
|
+
resolved = targetDir;
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
// 相对路径
|
|
171
|
+
resolved = resolve(baseDir, targetDir);
|
|
172
|
+
}
|
|
146
173
|
if (!existsSync(resolved))
|
|
147
174
|
throw new Error(`目录不存在: ${resolved}`);
|
|
148
175
|
const realPath = await realpath(resolved);
|
|
149
|
-
const allowed = this.allowedBaseDirs.some((base) => realPath === base || realPath.startsWith(base + '/'));
|
|
176
|
+
const allowed = this.allowedBaseDirs.some((base) => realPath === base || realPath.startsWith(base + '/') || realPath.startsWith(base + '\\'));
|
|
150
177
|
if (!allowed)
|
|
151
178
|
throw new Error(`目录不在允许范围内: ${realPath}`);
|
|
152
179
|
return realPath;
|