From 3d5a1a84a16646fd86994f011d285b72e8f71689 Mon Sep 17 00:00:00 2001
From: SHL-COOL <31879581+SHL-COOL@users.noreply.github.com>
Date: Thu, 27 Jun 2024 11:02:56 +0800
Subject: [PATCH] =?UTF-8?q?fix(m-team):=E4=BD=BF=E7=94=A8api=E5=9F=9F?=
=?UTF-8?q?=E5=90=8D=20(#1917)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* 修改馒头请求域名
* 修复种子页无法下载到
* 用户数据切换为api域名
* 搜索切换为api域名、支持种子页下载全部
* 增加api站点配置
* 适配搜索页跳转到网站
---
resource/i18n/en.json | 2 ++
resource/i18n/zh-CN.json | 2 ++
resource/sites/xp.m-team.cc/config.json | 6 ++++
.../xp.m-team.cc/getUserSeedingTorrents.js | 3 +-
resource/sites/xp.m-team.cc/torrents.js | 15 ++++++++--
src/background/controller.ts | 2 +-
src/background/searcher.ts | 16 ++++++++--
src/background/user.ts | 4 +++
src/content/index.ts | 2 +-
src/interface/common.ts | 3 +-
src/options/views/settings/Sites/Editor.vue | 30 +++++++++++++++++++
src/service/public.ts | 4 ++-
12 files changed, 77 insertions(+), 12 deletions(-)
diff --git a/resource/i18n/en.json b/resource/i18n/en.json
index ce11bdc03..93f375816 100644
--- a/resource/i18n/en.json
+++ b/resource/i18n/en.json
@@ -766,7 +766,9 @@
"disableSearchTransform": "Disable search transform",
"allowGetUserInfo": "Allow access to user information (Beta)",
"cdn": "Site CDN list",
+ "apiCdn": "Site API CDN list",
"cdnTip": "If you use a different URL than the system definition, you can fill in the currently used website address, fill in one address per line, the first one will be used as the address used for the search.",
+ "apiCdnTip": "priority over CDN list, fill in one address per line, the first one will be used as the address used for the request.",
"priority": "Priority",
"priorityTip": "Can be used for search sorting",
"offline": "Site is offline (downtime\/shutdown)",
diff --git a/resource/i18n/zh-CN.json b/resource/i18n/zh-CN.json
index d1d144759..c0ebf1909 100644
--- a/resource/i18n/zh-CN.json
+++ b/resource/i18n/zh-CN.json
@@ -761,7 +761,9 @@
"disableSearchTransform": "禁用搜索替换",
"allowGetUserInfo": "允许获取用户信息(Beta)",
"cdn": "站点CDN列表",
+ "apiCdn": "站点APICDN列表",
"cdnTip": "如您使用的网址和系统定义的不同,可在此填写当前使用的网站地址,每行填写一个地址,第一个将做为搜索时使用的地址",
+ "apiCdnTip": "优先级大于cdn,每行填写一个地址,第一个将做为请求时使用的地址",
"priority": "优先级",
"priorityTip": "可用于搜索排序",
"offline": "站点已离线(停机/关闭)",
diff --git a/resource/sites/xp.m-team.cc/config.json b/resource/sites/xp.m-team.cc/config.json
index 932fd19bc..231f36c5c 100644
--- a/resource/sites/xp.m-team.cc/config.json
+++ b/resource/sites/xp.m-team.cc/config.json
@@ -16,6 +16,12 @@
"https://xp.m-team.cc/",
"https://ap.m-team.cc/"
],
+ "apiCdn":[
+ "https://api.m-team.io/",
+ "https://api.m-team.cc/",
+ "https://api2.m-team.cc/",
+ "https://mtapi.m-team.cc/"
+ ],
"tokenRequired": true,
"formerHosts": [
"xp.m-team.io",
diff --git a/resource/sites/xp.m-team.cc/getUserSeedingTorrents.js b/resource/sites/xp.m-team.cc/getUserSeedingTorrents.js
index e9843b9f9..ace5e8bd0 100644
--- a/resource/sites/xp.m-team.cc/getUserSeedingTorrents.js
+++ b/resource/sites/xp.m-team.cc/getUserSeedingTorrents.js
@@ -137,8 +137,7 @@
}
return resolvedUrl.toString();
}
-
- let activeURL = options.site.activeURL
+ let activeURL = PPF.getSiteActiveUrl(site);
console.log(`[mt] getUserSeedingTorrents`, options, User);
let dataURL = resolveURL(activeURL, options.rule.page);
diff --git a/resource/sites/xp.m-team.cc/torrents.js b/resource/sites/xp.m-team.cc/torrents.js
index 765d39ab4..7d9a374f5 100644
--- a/resource/sites/xp.m-team.cc/torrents.js
+++ b/resource/sites/xp.m-team.cc/torrents.js
@@ -19,9 +19,18 @@
// eslint-disable-next-line
async resolveDownloadURLs() {
let ids = $('tr').map(function () {
- return $(this).data('row-key')
- }).toArray().filter(_ => !!_)
- ids = [...new Set(ids)]
+ let rowIds = $(this).find('td').map(function() {
+ let href = $(this).find('a').attr('href');
+ if (href) {
+ let match = href.match(/\/detail\/(\d+)/);
+ return match ? match[1] : null;
+ }
+ }).toArray().filter(id => !!id);
+
+ return rowIds;
+ }).toArray().flat().filter(id => !!id);
+
+ ids = [...new Set(ids)];
console.log('ids', ids)
let urls = []
return new Promise(async (resolve, reject) => {
diff --git a/src/background/controller.ts b/src/background/controller.ts
index 3a477084c..3c15c3153 100644
--- a/src/background/controller.ts
+++ b/src/background/controller.ts
@@ -476,7 +476,7 @@ export default class Controller {
*/
public getSiteFromHost(host: string): Site {
return this.options.sites.find((item: Site) => {
- let cdn = [item.url].concat(item.cdn);
+ let cdn = [item.url].concat(item.cdn, item.apiCdn);
return item.host == host || cdn.join("").indexOf(host) > -1;
});
}
diff --git a/src/background/searcher.ts b/src/background/searcher.ts
index 17a181012..0335553ab 100644
--- a/src/background/searcher.ts
+++ b/src/background/searcher.ts
@@ -379,8 +379,8 @@ export class Searcher {
? this.options.search.rows
: 10;
- // 如果有自定义地址,则使用自定义地址
- if (site.cdn && site.cdn.length > 0) {
+ if (site.cdn && site.cdn.length > 0) {
+ // 如果有自定义地址,则使用自定义地址
site.url = site.cdn[0];
}
@@ -391,7 +391,17 @@ export class Searcher {
if ((searchPage + "").substr(0, 1) == "/") {
searchPage = (searchPage + "").substr(1);
}
- let url: string = site.url + searchPage;
+ let url: string = "";
+
+ if (site.apiCdn && site.apiCdn.length > 0) {
+ if (!site.apiCdn[0].endsWith("/")) {
+ site.apiCdn[0] += "/";
+ }
+ // 如果有api地址,则使用api地址请求
+ url = site.apiCdn[0] + searchPage;
+ } else {
+ url = site.url + searchPage;
+ }
if (queryString) {
if (searchPage.indexOf("?") !== -1) {
diff --git a/src/background/user.ts b/src/background/user.ts
index 3d27e4e8d..9982260c6 100644
--- a/src/background/user.ts
+++ b/src/background/user.ts
@@ -63,6 +63,10 @@ export class User {
}
private getSiteURL(site: Site) {
+ if (site.apiCdn && site.apiCdn.length > 0) {
+ return site.apiCdn[0];
+ }
+
if (site.cdn && site.cdn.length > 0) {
return site.cdn[0];
}
diff --git a/src/content/index.ts b/src/content/index.ts
index 2ca13cccf..d96aa76bc 100644
--- a/src/content/index.ts
+++ b/src/content/index.ts
@@ -151,7 +151,7 @@ class PTPContent {
}
let site = sites.find((item: Site) => {
- let cdn = [item.url].concat(item.cdn);
+ let cdn = [item.url].concat(item.cdn, item.apiCdn);
return item.host == host || cdn.join("").indexOf(`//${host}`) > -1;
});
diff --git a/src/interface/common.ts b/src/interface/common.ts
index 07fa50139..cd55ed632 100644
--- a/src/interface/common.ts
+++ b/src/interface/common.ts
@@ -315,7 +315,8 @@ export interface Site {
// 使用站点标签进行分组
// siteGroups?: string[];
// token in headers
- authToken?: string
+ authToken?: string;
+ apiCdn?: string[];
}
/**
diff --git a/src/options/views/settings/Sites/Editor.vue b/src/options/views/settings/Sites/Editor.vue
index 65a8526a8..f98f157df 100644
--- a/src/options/views/settings/Sites/Editor.vue
+++ b/src/options/views/settings/Sites/Editor.vue
@@ -112,6 +112,13 @@
:hint="$t('settings.sites.editor.cdnTip')"
>
+
+
`${u.desc},${u.href},${u.color ? u.color : ''}`).join('\n')
} else {
@@ -415,6 +431,20 @@ export default Vue.extend({
this.site.cdn = result;
},
+ apiCdn() {
+ let items = this.apiCdn.split("\n");
+ let result: string[] = [];
+ items.forEach(apiCdn => {
+ if (
+ /(https?):\/\/[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]/.test(
+ apiCdn
+ )
+ ) {
+ result.push(apiCdn);
+ }
+ });
+ this.site.apiCdn = result;
+ },
quickLinkText() {
this.site.userQuickLinks = this.quickLinkText.split(/\n/).filter(_ => !!_)
.map(_ => _.split(/\s*[,,]\s*/)).filter(([desc, href, color]) => {
diff --git a/src/service/public.ts b/src/service/public.ts
index 36bad3971..b78525441 100644
--- a/src/service/public.ts
+++ b/src/service/public.ts
@@ -372,10 +372,11 @@ class HelpFunctions {
}
let site = sites.find((item: Site) => {
- let cdn = [item.url].concat(item.cdn, item.formerHosts?.map(x => `//${x}`));
+ let cdn = [item.url].concat(item.cdn, item.apiCdn, item.formerHosts?.map(x => `//${x}`));
return item.host == host || cdn.join("").indexOf(`//${host}`) > -1;
});
+
if (site) {
return this.clone(site);
}
@@ -487,6 +488,7 @@ class HelpFunctions {
* 比如右键种子发送到 PTPP, 按正常逻辑筛选一遍
*/
public getSiteActiveUrl(site: Site) {
+ if (site.apiCdn && site.apiCdn.length > 0) return site.apiCdn[0]
if (site.activeURL) return site.activeURL
if (site.cdn && site.cdn.length > 0) return site.cdn[0]
return site.url