fix: 修复mediabot拉取风险规则失败的三个问题

1. HMAC拦截器跳过GET请求,mediabot拉取规则不再被401拦截
2. findByIdentifier增加site_type回退查找,兼容按site_type查询
3. saveRules自动填充site_type字段,从站点表获取
4. GET接口version参数支持非数字值如latest
This commit is contained in:
mediabot-pt
2026-07-07 00:33:46 +08:00
parent 15a3c381d0
commit a0780c64bb
3 changed files with 25 additions and 5 deletions

View File

@@ -21,14 +21,16 @@ public class RiskRuleController {
@GetMapping("/api/v1/risk-rules/{siteType}")
public ResponseEntity<?> getRules(@PathVariable String siteType,
@RequestParam(defaultValue = "0") int version,
@RequestParam(defaultValue = "0") String version,
@RequestParam(defaultValue = "") String source) {
int ver;
try { ver = Integer.parseInt(version); } catch (NumberFormatException e) { ver = 0; }
// 先尝试自定义规则
int currentVer = riskRuleService.getVersion(siteType);
Map<String, Object> data = riskRuleService.getRules(siteType);
if (data != null) {
data.put("source", "custom");
if (currentVer == version && "custom".equals(source)) return ResponseEntity.status(304).build();
if (currentVer == ver && "custom".equals(source)) return ResponseEntity.status(304).build();
return ResponseEntity.ok(data);
}
// 回退默认模板
@@ -36,7 +38,7 @@ public class RiskRuleController {
Map<String, Object> defData = riskRuleService.getRules("default:" + siteType);
if (defData != null) {
defData.put("source", "default");
if (defVer == version && "default".equals(source)) return ResponseEntity.status(304).build();
if (defVer == ver && "default".equals(source)) return ResponseEntity.status(304).build();
return ResponseEntity.ok(defData);
}
return ResponseEntity.status(304).build();