feat: 四类站点默认脚本+无自定义脚本时按siteType自动加载默认模板
This commit is contained in:
@@ -26,6 +26,7 @@ public class AdapterController {
|
||||
private final SiteConfigMapper siteConfigMapper;
|
||||
private final AccessResultMapper accessResultMapper;
|
||||
private final CachedStorageService storageService;
|
||||
private final com.par.core.mapper.SiteMapper siteMapper;
|
||||
|
||||
/**
|
||||
* 用指定适配配置解析指定访问结果
|
||||
@@ -113,21 +114,28 @@ public class AdapterController {
|
||||
item.put("invalidCount", allResults.stream().filter(r -> url.equals(r.getUrl()) && Boolean.FALSE.equals(r.getIsValid())).count());
|
||||
item.put("uncheckedCount", allResults.stream().filter(r -> url.equals(r.getUrl()) && r.getIsValid() == null).count());
|
||||
|
||||
// 解析内容:必须有 Groovy 脚本
|
||||
// 解析内容:优先自定义脚本,否则用站点类型默认脚本
|
||||
try {
|
||||
if (siteConfig.getScriptStoragePath() == null || siteConfig.getScriptStoragePath().isBlank()) {
|
||||
item.put("parsed", Map.of("matched", false, "message", "该配置未绑定 Groovy 脚本"));
|
||||
String script;
|
||||
if (siteConfig.getScriptStoragePath() != null && !siteConfig.getScriptStoragePath().isBlank()) {
|
||||
script = storageService.read(siteConfig.getScriptStoragePath());
|
||||
} else {
|
||||
String script = storageService.read(siteConfig.getScriptStoragePath());
|
||||
if (script == null || script.isBlank()) {
|
||||
item.put("parsed", Map.of("matched", false, "message", "Groovy 脚本为空"));
|
||||
script = null;
|
||||
}
|
||||
if (script == null || script.isBlank()) {
|
||||
// 加载站点类型默认脚本
|
||||
var site = siteMapper.selectBySiteId(siteId);
|
||||
String st = site != null && site.getSiteType() != null ? site.getSiteType().getValue() : null;
|
||||
script = GroovyScriptEngine.loadDefaultByType(st);
|
||||
}
|
||||
if (script == null || script.isBlank()) {
|
||||
item.put("parsed", Map.of("matched", false, "message", "未绑定脚本且无默认模板"));
|
||||
} else {
|
||||
String content = storageService.read(ar.getStoragePath());
|
||||
if (content == null) {
|
||||
item.put("parsed", Map.of("matched", false, "message", "内容为空"));
|
||||
} else {
|
||||
String content = storageService.read(ar.getStoragePath());
|
||||
if (content == null) {
|
||||
item.put("parsed", Map.of("matched", false, "message", "内容为空"));
|
||||
} else {
|
||||
item.put("parsed", groovyEngine.execute(script, content, url));
|
||||
}
|
||||
item.put("parsed", groovyEngine.execute(script, content, url));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
Reference in New Issue
Block a user