From eb225d09363457b7163be95c8e3289abc6d36970 Mon Sep 17 00:00:00 2001 From: ypsdf1 Date: Mon, 8 Jun 2026 13:12:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20BaoTa=E7=AC=AC=E4=B8=89=E8=B7=AF?= =?UTF-8?q?=E5=A4=87=E9=80=89=E6=9B=B4=E6=96=B0=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Main: 添加BaoTa HTML第三路备选通道,GitHub/Gitee限流后自动降级 --- .idea/misc.xml | 2 +- pom.xml | 10 +-- src/main/java/com/sdf1/Main.java | 105 +++++++++++++++++++++++++++++-- 3 files changed, 105 insertions(+), 12 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 1c302b2..147f7f3 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -8,7 +8,7 @@ - + \ No newline at end of file diff --git a/pom.xml b/pom.xml index c0726ef..e4d770d 100644 --- a/pom.xml +++ b/pom.xml @@ -10,8 +10,8 @@ UTF-8 - 21 - 21 + 25 + 25 @@ -49,10 +49,10 @@ org.apache.maven.plugins maven-compiler-plugin - 3.8.1 + 3.14.0 - 21 - 21 + 25 + 25 UTF-8 diff --git a/src/main/java/com/sdf1/Main.java b/src/main/java/com/sdf1/Main.java index 6bc6767..7af4bad 100644 --- a/src/main/java/com/sdf1/Main.java +++ b/src/main/java/com/sdf1/Main.java @@ -64,6 +64,10 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor { private static final String API_GE = "https://gitee.com/api/v5/repos/nihaoshidifu/sdf1_plugn/releases/latest"; private static final String DL_GH = "https://github.com/ypsdf1/sdf1_plugn/releases"; private static final String DL_GE = "https://gitee.com/nihaoshidifu/sdf1_plugn/releases"; + + // 第三路备选:宝塔静态HTML + private static final String FALLBACK_HTML = "https://caoyuan.ypshidifu.cn/update_check.html"; + private static final String[] CY_DISCOVER_NAMES = {"CY_beibao", "CY", "cy_beibao", "Cy", "cy"}; private Plugin discoveredCy = null; private java.lang.reflect.Method discoveredCyActivate = null; @@ -2439,8 +2443,16 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor { log("[更新] " + pName + " 失败,切换 " + bName); result = fetchRelease(bApi, bName); if (result != null) { applyUpdate(result[0], result[1], bDl, manual, bName); return; } - log("双路均失败"); - if (manual != null) manual.sendMessage("[更新] 检查失败"); + // ★ 双路均失败,尝试第三路备选(宝塔静态HTML) + log("[更新] GitHub/Gitee 均失败,尝试第三路备选 BaoTa..."); + String[] fbResult = tryFallbackChannel(); + if (fbResult != null) { + log("[更新] 第三路备选 BaoTa 检查成功: " + fbResult[0]); + applyUpdate(fbResult[0], fbResult[1], DL_GH, manual, "BaoTa"); + return; + } + log("[更新] 三路均失败"); + if (manual != null) manual.sendMessage("[更新] 检查失败(含宝塔备选)"); } catch (Exception e) { log("异常: " + e.getMessage()); } }}).start(); } @@ -2452,14 +2464,21 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor { SSLContext sc = SSLContext.getInstance("TLS"); sc.init(null, trustAll, new java.security.SecureRandom()); URL url = new URL(apiUrl); c = (HttpURLConnection) url.openConnection(); if (c instanceof HttpsURLConnection) { HttpsURLConnection hc = (HttpsURLConnection) c; hc.setSSLSocketFactory(sc.getSocketFactory()); hc.setHostnameVerifier(new javax.net.ssl.HostnameVerifier(){public boolean verify(String h,javax.net.ssl.SSLSession sess){return true;}}); } - c.setRequestMethod("GET"); c.setRequestProperty("User-Agent", + c.setRequestMethod("GET"); + c.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 " - + "(KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"); + + "(KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36"); c.setRequestProperty("Accept", "*/*"); - c.setRequestProperty("Accept-Language", "zh-CN,zh;q=0.9"); + c.setRequestProperty("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8"); + c.setRequestProperty("Connection", "keep-alive"); c.setConnectTimeout(15000); c.setReadTimeout(15000); c.setInstanceFollowRedirects(true); int code = c.getResponseCode(); - if (code != 200) { log(ch + " HTTP " + code); return null; } + if (code != 200) { + String errBody = ""; + try { errBody = readStream(c.getErrorStream()); } catch (Exception ignored) {} + log(ch + " HTTP " + code + (errBody.isEmpty() ? "" : " | " + errBody.substring(0, Math.min(errBody.length(), 200)))); + return null; + } String json = readStream(c.getInputStream()); if (json == null || json.isEmpty()) { log(ch + " 响应为空"); return null; } String rv = jParse(json, "tag_name"); String rn = jParse(json, "body"); @@ -2478,6 +2497,80 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor { catch (Exception e) { log("[更新] 读取流失败: " + e.getMessage()); return null; } } + /** + * 第三路备选:从宝塔静态HTML解析版本信息 + * HTML中用 块 + String html = sb.toString(); + int start = html.indexOf(""); + if (start < 0 || end < 0 || end <= start) { + log("[更新] BaoTa: 无法解析更新数据块"); + return null; + } + String block = html.substring(start, end); + + // ★ 去除 Cloudflare 注入的 CDN-CGI 链接(...) + block = block.replaceAll("]*>[^<]*", ""); + + // 逐行查找匹配 sdf1 的记录 + String[] lines = block.split("\n"); + for (String l : lines) { + l = l.trim(); + // 跳过空行、注释标记行、HTML注入标签 + if (l.isEmpty() || l.startsWith("