Skip to content

Commit

Permalink
fix(m-team):使用api域名 (#1917)
Browse files Browse the repository at this point in the history
* 修改馒头请求域名

* 修复种子页无法下载到

* 用户数据切换为api域名

* 搜索切换为api域名、支持种子页下载全部

* 增加api站点配置

* 适配搜索页跳转到网站
  • Loading branch information
SHL-COOL authored Jun 27, 2024
1 parent f86dd50 commit 3d5a1a8
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 12 deletions.
2 changes: 2 additions & 0 deletions resource/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
2 changes: 2 additions & 0 deletions resource/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,9 @@
"disableSearchTransform": "禁用搜索替换",
"allowGetUserInfo": "允许获取用户信息(Beta)",
"cdn": "站点CDN列表",
"apiCdn": "站点APICDN列表",
"cdnTip": "如您使用的网址和系统定义的不同,可在此填写当前使用的网站地址,每行填写一个地址,第一个将做为搜索时使用的地址",
"apiCdnTip": "优先级大于cdn,每行填写一个地址,第一个将做为请求时使用的地址",
"priority": "优先级",
"priorityTip": "可用于搜索排序",
"offline": "站点已离线(停机/关闭)",
Expand Down
6 changes: 6 additions & 0 deletions resource/sites/xp.m-team.cc/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions resource/sites/xp.m-team.cc/getUserSeedingTorrents.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 12 additions & 3 deletions resource/sites/xp.m-team.cc/torrents.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/background/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
Expand Down
16 changes: 13 additions & 3 deletions src/background/searcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand All @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions src/background/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
2 changes: 1 addition & 1 deletion src/content/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});

Expand Down
3 changes: 2 additions & 1 deletion src/interface/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@ export interface Site {
// 使用站点标签进行分组
// siteGroups?: string[];
// token in headers
authToken?: string
authToken?: string;
apiCdn?: string[];
}

/**
Expand Down
30 changes: 30 additions & 0 deletions src/options/views/settings/Sites/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@
:hint="$t('settings.sites.editor.cdnTip')"
></v-textarea>

<v-textarea
v-model="apiCdn"
:label="$t('settings.sites.editor.apiCdn')"
value
:hint="$t('settings.sites.editor.cdnTip')"
></v-textarea>

<!-- 时区 -->
<v-autocomplete
v-model="site.timezoneOffset"
Expand Down Expand Up @@ -238,6 +245,7 @@ export default Vue.extend({
}
},
cdn: "",
apiCdn: "",
quickLinkText: "",
valid: false,
site: {} as Site,
Expand Down Expand Up @@ -382,6 +390,14 @@ export default Vue.extend({
} else {
this.cdn = "";
}
if (this.site.apiCdn) {
this.apiCdn = this.site.apiCdn.join("\n");
} else {
this.apiCdn = "";
}
if (this.site.userQuickLinks) {
this.quickLinkText = this.site.userQuickLinks.map(u => `${u.desc},${u.href},${u.color ? u.color : ''}`).join('\n')
} else {
Expand Down Expand Up @@ -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]) => {
Expand Down
4 changes: 3 additions & 1 deletion src/service/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3d5a1a8

Please sign in to comment.