refactor: parse统一用pageKey路由,移除URL回退逻辑
This commit is contained in:
@@ -62,7 +62,7 @@ public class AdapterController {
|
|||||||
catch (Exception e) { return ApiResponse.error(500, "读取内容失败: " + e.getMessage()); }
|
catch (Exception e) { return ApiResponse.error(500, "读取内容失败: " + e.getMessage()); }
|
||||||
if (content == null) return ApiResponse.error(404, "内容为空");
|
if (content == null) return ApiResponse.error(404, "内容为空");
|
||||||
|
|
||||||
String pageKey = resolvePageKey(siteConfig.getSiteId(), accessResult.getUrl());
|
String pageKey = (String) payload.getOrDefault("pageKey", resolvePageKey(siteConfig.getSiteId(), accessResult.getUrl()));
|
||||||
return ApiResponse.success(groovyEngine.execute(script, content, accessResult.getUrl(), pageKey));
|
return ApiResponse.success(groovyEngine.execute(script, content, accessResult.getUrl(), pageKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -145,11 +145,7 @@ public class GroovyScriptEngine {
|
|||||||
binding.setVariable("http", HttpUtils.INSTANCE);
|
binding.setVariable("http", HttpUtils.INSTANCE);
|
||||||
|
|
||||||
GroovyShell shell = new GroovyShell(classLoader, binding);
|
GroovyShell shell = new GroovyShell(classLoader, binding);
|
||||||
// 优先用 pageKey 路由,无则回退 url 路由
|
String fullScript = SCRIPT_PREFIX + groovyScript + "\n// PAR 调用入口\nreturn parse(content, pageKey)";
|
||||||
String call = pageKey != null && !pageKey.isEmpty()
|
|
||||||
? "return parse(content, pageKey)"
|
|
||||||
: "return parse(content, url)";
|
|
||||||
String fullScript = SCRIPT_PREFIX + groovyScript + "\n// PAR 调用入口\n" + call;
|
|
||||||
Object scriptResult = shell.evaluate(fullScript);
|
Object scriptResult = shell.evaluate(fullScript);
|
||||||
|
|
||||||
return buildResult(result, scriptResult);
|
return buildResult(result, scriptResult);
|
||||||
|
|||||||
@@ -10,15 +10,7 @@ Map parse(String content, String pageKey) {
|
|||||||
case 'download': return parseDownload(content)
|
case 'download': return parseDownload(content)
|
||||||
case 'sync': return parseUserInfo(doc)
|
case 'sync': return parseUserInfo(doc)
|
||||||
case 'rss': return parseRss(content)
|
case 'rss': return parseRss(content)
|
||||||
default:
|
default: return [pageName: '未知页面', error: "未知 pageKey: ${pageKey}"]
|
||||||
// fallback: pageKey 未知时用 URL 兜底
|
|
||||||
String u = url ?: ''
|
|
||||||
if (u.contains('/attendance.php')) return parseSign(doc)
|
|
||||||
if (u.contains('/download.php')) return parseDownload(content)
|
|
||||||
if (u.contains('/index.php') && !u.contains('?')) return parseUserInfo(doc)
|
|
||||||
if (u.contains('/usercp.php')) return parseUserPanel(doc)
|
|
||||||
if (u.contains('/torrentrss.php') || u.contains('/rss')) return parseRss(content)
|
|
||||||
return [pageName: '未知页面', message: "未配置: pageKey=${pageKey}"]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user