refactor: detail仅作子请求不设独立脚本入口
This commit is contained in:
@@ -6,10 +6,20 @@
|
||||
// medibo 根据 pageKey 调用对应方法,如 parseSync(context)
|
||||
// 约定方法名: parse + pageKey 首字母大写
|
||||
|
||||
Map parseSync(context) { return checkStatus(context) ?: parseUserProfile(Jsoup.parse(context.content)) }
|
||||
Map parseSearch(context) { return checkStatus(context) ?: parseSearchPage(Jsoup.parse(context.content)) }
|
||||
Map parseDetail(context) { return checkStatus(context) ?: parseDetailPage(Jsoup.parse(context.content)) }
|
||||
Map parseSignIn(context) { return checkStatus(context) ?: parseSignPage(Jsoup.parse(context.content)) }
|
||||
// medibo 直接调用的入口方法
|
||||
Map parseSync(context) {
|
||||
if (context.status != 200) return [matched: false, error: true, status: context.status]
|
||||
def doc = Jsoup.parse(context.content)
|
||||
def profile = parseUserProfile(doc)
|
||||
// 如果需要详情,通过 context.fetch 子请求
|
||||
if (profile.matched && false /* 需要详情 */) {
|
||||
def resp = context.fetch("detail", [id: "xxx"])
|
||||
if (resp.status == 200) profile.detail = parseDetailPage(Jsoup.parse(resp.content))
|
||||
}
|
||||
return profile
|
||||
}
|
||||
Map parseSearch(context) { return checkStatus(context) ?: parseSearchPage(Jsoup.parse(context.content)) }
|
||||
Map parseSignIn(context) { return checkStatus(context) ?: parseSignPage(Jsoup.parse(context.content)) }
|
||||
Map parseDownload(context) { return checkStatus(context) ?: parseDownloadPage(context) }
|
||||
|
||||
/** 通用状态码检查,非 200 直接返回错误 */
|
||||
|
||||
@@ -9,8 +9,9 @@ public enum PageKey {
|
||||
SYNC("sync", "同步", "GET"),
|
||||
SIGN_IN("signIn", "签到", "POST"),
|
||||
SEARCH("search", "搜索", "GET"),
|
||||
DETAIL("detail", "资源详情", "GET"),
|
||||
DOWNLOAD("download", "下载", "GET");
|
||||
DOWNLOAD("download", "下载", "GET"),
|
||||
// detail 仅供脚本内 context.fetch("detail", ...) 使用,medibo 不直接调用
|
||||
DETAIL("detail", "资源详情", "GET");
|
||||
|
||||
private final String key;
|
||||
private final String label;
|
||||
|
||||
Reference in New Issue
Block a user