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

@@ -46,6 +46,12 @@ public class HmacAuthInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
// 只拦截写入操作(PUT/POST/DELETE/PATCH),GET/HEAD/OPTIONS 直接放行
String method = request.getMethod().toUpperCase();
if ("GET".equals(method) || "HEAD".equals(method) || "OPTIONS".equals(method)) {
return true;
}
// 方式 1:Bearer Token
String authHeader = request.getHeader("Authorization");
if (authHeader != null && authHeader.startsWith("Bearer ")) {

View File

@@ -20,12 +20,19 @@ public class RiskRuleServiceImpl implements RiskRuleService {
private final ManifestVersionService versionService;
private final RiskRuleMapper mapper;
private final com.par.core.storage.CachedStorageService storageService;
private final com.par.core.service.SiteService siteService;
private static final ObjectMapper om = new ObjectMapper();
private RiskRule findByIdentifier(String identifier) {
return mapper.selectOne(new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<RiskRule>()
// 先按 site_id 查找
RiskRule rr = mapper.selectOne(new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<RiskRule>()
.eq(RiskRule::getSiteId, identifier).eq(RiskRule::getDeleted, 0)
.orderByDesc(RiskRule::getId).last("limit 1"));
if (rr != null) return rr;
// 回退按 site_type 查找(兼容旧数据及 mediabot 按 site_type 查询)
return mapper.selectOne(new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<RiskRule>()
.eq(RiskRule::getSiteType, identifier).eq(RiskRule::getDeleted, 0)
.orderByDesc(RiskRule::getId).last("limit 1"));
}
@Override
@@ -58,7 +65,12 @@ public class RiskRuleServiceImpl implements RiskRuleService {
String json = om.writerWithDefaultPrettyPrinter().writeValueAsString(rules);
int nextVer = getVersion(siteType) + 1;
RiskRule rr = new RiskRule();
rr.setSiteId(siteType); // siteType param now carries the identifier (siteId)
rr.setSiteId(siteType);
// 从站点表查找 site_type,使 mediabot 可按 site_type 查询
var site = siteService.findBySiteId(siteType);
if (site != null && site.getSiteType() != null) {
rr.setSiteType(site.getSiteType().getValue());
}
rr.setVersion(nextVer);
rr.setRulesJson(json);
mapper.insert(rr);