refactor: 移除 verify 和 detectAnnounce 方法
This commit is contained in:
@@ -90,22 +90,6 @@ Map sync(PluginContext ctx) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Map verify(PluginContext ctx) {
|
|
||||||
if (!ctx.site.authorization) return [available: false, reason: "未配置 Token"]
|
|
||||||
try {
|
|
||||||
def resp = apiGet(ctx, "/api/member/profile")
|
|
||||||
if (resp.statusCode() == 200) {
|
|
||||||
def json = new groovy.json.JsonSlurper().parseText(resp.body())
|
|
||||||
return json.message == "SUCCESS"
|
|
||||||
? [available: true, reason: "Token 验证通过"]
|
|
||||||
: [available: false, reason: "Token 无效"]
|
|
||||||
}
|
|
||||||
return [available: false, reason: "HTTP ${resp.statusCode()}"]
|
|
||||||
} catch (e) {
|
|
||||||
return [available: false, reason: "连接失败: ${e.message}"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
List search(PluginContext ctx, Map params) {
|
List search(PluginContext ctx, Map params) {
|
||||||
if (!ctx.site.authorization) return []
|
if (!ctx.site.authorization) return []
|
||||||
try {
|
try {
|
||||||
@@ -137,43 +121,6 @@ List search(PluginContext ctx, Map params) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Map detectAnnounce(PluginContext ctx) {
|
|
||||||
if (!ctx.site.authorization) return [error: "未配置 Token"]
|
|
||||||
try {
|
|
||||||
// 搜索任意种子获取 ID
|
|
||||||
def body = groovy.json.JsonOutput.toJson([keyword: "", pageNumber: 1, pageSize: 1, visible: 1])
|
|
||||||
def resp = apiPost(ctx, "/api/torrent/search", body)
|
|
||||||
def json = new groovy.json.JsonSlurper().parseText(resp.body())
|
|
||||||
def item = json?.data?.data?.get(0)
|
|
||||||
if (!item?.id) return [error: "未找到种子"]
|
|
||||||
|
|
||||||
// 生成下载 Token
|
|
||||||
def dlBody = groovy.json.JsonOutput.toJson([id: item.id.toString()])
|
|
||||||
def dlResp = apiPost(ctx, "/api/torrent/genDlToken", dlBody)
|
|
||||||
def dlJson = new groovy.json.JsonSlurper().parseText(dlResp.body())
|
|
||||||
def token = dlJson?.data
|
|
||||||
if (!token) return [error: "获取下载 Token 失败"]
|
|
||||||
|
|
||||||
// 下载种子文件
|
|
||||||
def torResp = ctx.httpClient.send(
|
|
||||||
java.net.http.HttpRequest.newBuilder()
|
|
||||||
.uri(new java.net.URI("${ctx.siteUrl}download/${item.id}/${token}"))
|
|
||||||
.timeout(java.time.Duration.ofSeconds(30))
|
|
||||||
.header("User-Agent", "Mozilla/5.0")
|
|
||||||
.GET().build(),
|
|
||||||
java.net.http.HttpResponse.BodyHandlers.ofByteArray())
|
|
||||||
|
|
||||||
if (torResp.statusCode() != 200 || !torResp.body()) return [error: "种子下载失败"]
|
|
||||||
def info = com.mediabot.util.Bencode.decode(torResp.body())
|
|
||||||
def announce = info?.announce
|
|
||||||
return announce && announce.toString().startsWith("http")
|
|
||||||
? [announceUrl: announce.toString()]
|
|
||||||
: [error: "解析失败"]
|
|
||||||
} catch (e) {
|
|
||||||
return [error: e.message]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ==================== 工具方法 ====================
|
// ==================== 工具方法 ====================
|
||||||
|
|
||||||
private def apiGet(PluginContext ctx, String path) {
|
private def apiGet(PluginContext ctx, String path) {
|
||||||
|
|||||||
Reference in New Issue
Block a user