refactor: parse(content,pageKey)替代URL路由,新增resolvePageKey
This commit is contained in:
@@ -127,19 +127,29 @@ public class GroovyScriptEngine {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, Object> execute(String groovyScript, String content, String url) {
|
||||
return execute(groovyScript, content, url, null);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, Object> execute(String groovyScript, String content, String url, String pageKey) {
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
result.put("engine", "groovy");
|
||||
try {
|
||||
Binding binding = new Binding();
|
||||
binding.setVariable("content", content);
|
||||
binding.setVariable("url", url);
|
||||
binding.setVariable("pageKey", pageKey != null ? pageKey : "");
|
||||
binding.setVariable("jsoup", new JsoupHelper());
|
||||
binding.setVariable("json", objectMapper);
|
||||
binding.setVariable("utils", new ScriptUtils());
|
||||
binding.setVariable("http", HttpUtils.INSTANCE);
|
||||
|
||||
GroovyShell shell = new GroovyShell(classLoader, binding);
|
||||
String fullScript = SCRIPT_PREFIX + groovyScript + "\n// PAR 调用入口\nreturn parse(content, url)";
|
||||
// 优先用 pageKey 路由,无则回退 url 路由
|
||||
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);
|
||||
|
||||
return buildResult(result, scriptResult);
|
||||
|
||||
@@ -1,18 +1,25 @@
|
||||
// NexusPHP 站点默认脚本
|
||||
// 适用: PThome / HDSky / HDFans / OurBits 等
|
||||
|
||||
Map parse(String content, String url) {
|
||||
Map parse(String content, String pageKey) {
|
||||
def doc = Jsoup.parse(content)
|
||||
|
||||
if (url.contains('/torrents.php')) return parseSearch(doc)
|
||||
if (url.contains('/details.php')) return parseDetail(doc)
|
||||
if (url.contains('/attendance.php')) return parseSign(doc)
|
||||
if (url.contains('/download.php')) return parseDownload(content)
|
||||
if (url.contains('/index.php') && !url.contains('?')) return parseUserInfo(doc)
|
||||
if (url.contains('/usercp.php')) return parseUserPanel(doc)
|
||||
if (url.contains('/torrentrss.php') || url.contains('/rss')) return parseRss(content)
|
||||
|
||||
return [pageName: '未知页面', message: "未配置: ${url}"]
|
||||
switch (pageKey) {
|
||||
case 'search': return parseSearch(doc)
|
||||
case 'detail': return parseDetail(doc)
|
||||
case 'signIn': return parseSign(doc)
|
||||
case 'download': return parseDownload(content)
|
||||
case 'sync': return parseUserInfo(doc)
|
||||
case 'rss': return parseRss(content)
|
||||
default:
|
||||
// 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}"]
|
||||
}
|
||||
}
|
||||
|
||||
private Map parseDownload(String content) {
|
||||
|
||||
Reference in New Issue
Block a user