第76批:黑名单相对路径根目录修复(./开头以openai目录为根)
Auto Release / build (push) Successful in 2m22s

This commit is contained in:
youpaishidifu
2026-11-04 09:10:33 +08:00
parent 9067bb00a1
commit b454cfe5ba
+19 -3
View File
@@ -1795,14 +1795,30 @@ public class AIChatManager {
*/ */
private void loadBlacklistFromPath(String rawPath) { private void loadBlacklistFromPath(String rawPath) {
if (rawPath == null || rawPath.isEmpty()) return; if (rawPath == null || rawPath.isEmpty()) return;
// 统一转为相对路径:/ 开头 → 视为插件数据目录根 // 统一转为相对路径
String relPath = rawPath.replace('\\', '/'); String relPath = rawPath.replace('\\', '/');
// ★ 第76批:./ 开头的路径以 openai 目录为根(与增量扫描 openai/黑名单 一致)
// 原来用 plugin.getDataFolder() 作为根,导致 ./黑名单 解析到 plugins/Sdf1_login/黑名单,
// 而实际黑名单文件在 plugins/Sdf1_login/openai/黑名单/ → 找不到
File baseDir;
if (relPath.startsWith("/")) { if (relPath.startsWith("/")) {
// / 开头 → 插件数据目录根
relPath = relPath.substring(1); relPath = relPath.substring(1);
baseDir = plugin.getDataFolder();
} else if (relPath.startsWith("./") || relPath.startsWith(".")) {
// ./ 开头 → openai 目录根
File openaiDir = new File(plugin.getDataFolder(), "openai");
baseDir = openaiDir;
if (relPath.startsWith("./")) relPath = relPath.substring(2);
else if (relPath.startsWith(".")) relPath = relPath.substring(1);
if (relPath.startsWith("/")) relPath = relPath.substring(1);
} else {
// 无前缀 → 插件数据目录根
baseDir = plugin.getDataFolder();
} }
// 安全检查:不允许 .. 越出插件数据目录 // 安全检查:不允许 .. 越出插件数据目录
File pluginDir = plugin.getDataFolder(); File pluginDir = plugin.getDataFolder();
File resolved = new File(pluginDir, relPath); File resolved = new File(baseDir, relPath);
String pluginAbs = pluginDir.getAbsoluteFile().toPath().normalize().toString(); String pluginAbs = pluginDir.getAbsoluteFile().toPath().normalize().toString();
String resolvedAbs = resolved.getAbsoluteFile().toPath().normalize().toString(); String resolvedAbs = resolved.getAbsoluteFile().toPath().normalize().toString();
if (!resolvedAbs.equals(pluginAbs) && !resolvedAbs.startsWith(pluginAbs + java.io.File.separator)) { if (!resolvedAbs.equals(pluginAbs) && !resolvedAbs.startsWith(pluginAbs + java.io.File.separator)) {
@@ -1810,7 +1826,7 @@ public class AIChatManager {
return; return;
} }
if (!resolved.exists()) { if (!resolved.exists()) {
plugin.getLogger().warning("[AI聊天] 黑名单路径不存在,跳过: " + rawPath); plugin.getLogger().warning("[AI聊天] 黑名单路径不存在,跳过: " + rawPath + " → 解析为: " + resolved.getAbsolutePath());
return; return;
} }
try { try {