From 404bf729f4dccc4058ec75b132d69420fba73d2a Mon Sep 17 00:00:00 2001 From: mediabot-pt <295750538+mediabot-pt@users.noreply.github.com> Date: Wed, 1 Jul 2026 23:02:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=86=85=E5=AE=B9=E4=BB=A3=E7=90=86?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=9F=A5=E8=AF=A2=E5=8F=82=E6=95=B0+?= =?UTF-8?q?=E7=B2=BE=E7=A1=AE=E5=8C=B9=E9=85=8D+=E5=9B=9E=E9=80=80+JSON=20?= =?UTF-8?q?content-type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AccessResultController.java | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/par-api/src/main/java/com/par/api/controller/AccessResultController.java b/par-api/src/main/java/com/par/api/controller/AccessResultController.java index 5333424..9cc0d5f 100644 --- a/par-api/src/main/java/com/par/api/controller/AccessResultController.java +++ b/par-api/src/main/java/com/par/api/controller/AccessResultController.java @@ -38,6 +38,12 @@ public class AccessResultController { * Groovy 脚本中 httpGet(ctx, '/index.php') 通过此接口获取已存储的页面内容。 * ctx.siteUrl 指向:http://par:9012/api/v1/admin/sites/{siteId}/content */ + /** + * 内容代理:根据路径和可选查询参数返回存储内容。 + * 匹配规则:URL 以请求路径结尾(含查询参数),返回最新匹配项。 + * GET /admin/sites/{siteId}/content/index.php + * GET /admin/sites/{siteId}/content/torrents.php?search=keyword + */ @GetMapping("/api/v1/admin/sites/{siteId}/content/**") public ResponseEntity contentProxy( @PathVariable("siteId") String siteId, @@ -45,23 +51,35 @@ public class AccessResultController { String fullPath = request.getRequestURI(); String prefix = "/api/v1/admin/sites/" + siteId + "/content"; String relativePath = fullPath.substring(fullPath.indexOf(prefix) + prefix.length()); - if (relativePath.isEmpty()) relativePath = "/"; + String query = request.getQueryString(); + String pathWithQuery = relativePath + (query != null ? "?" + query : ""); + if (pathWithQuery.isEmpty()) pathWithQuery = "/"; - // 查找最新匹配的存储内容 List results = accessResultMapper.selectList( new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper() .eq(AccessResult::getSiteId, siteId) .orderByDesc(AccessResult::getId) - .last("limit 100")); - String path = relativePath; + .last("limit 200")); + + // 优先精确匹配(URL 以 pathWithQuery 结尾),否则模糊匹配 AccessResult best = results.stream() - .filter(r -> r.getUrl() != null && r.getStoragePath() != null && r.getUrl().contains(path)) + .filter(r -> r.getUrl() != null && r.getStoragePath() != null && + (r.getUrl().endsWith(pathWithQuery) || r.getUrl().contains(pathWithQuery))) .findFirst().orElse(null); + if (best == null) { + // 回退:URL 包含相对路径(不含查询参数) + String pathOnly = relativePath; + best = results.stream() + .filter(r -> r.getUrl() != null && r.getStoragePath() != null && r.getUrl().contains(pathOnly)) + .findFirst().orElse(null); + } if (best == null) return ResponseEntity.notFound().build(); String content = storageService.read(best.getStoragePath()); if (content == null) return ResponseEntity.notFound().build(); - return ResponseEntity.ok().contentType(MediaType.TEXT_HTML).body(content); + + String contentType = "json".equalsIgnoreCase(best.getContentType()) ? "application/json" : "text/html"; + return ResponseEntity.ok().contentType(MediaType.parseMediaType(contentType + ";charset=UTF-8")).body(content); } // ==================== mediabot 提交接口(PSK 鉴权) ====================