Skip to content

Commit

Permalink
feat: MT api 变更 #58
Browse files Browse the repository at this point in the history
  • Loading branch information
vertex-app committed Jun 21, 2024
1 parent c85d32c commit eb0b2ed
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 83 deletions.
5 changes: 3 additions & 2 deletions app/common/Site.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ class Site {
};
}

async _getDocument (url, origin = false, expire = 300, retCookies = false) {
async _getDocument (url, origin = false, expire = 300, retCookies = false, headers) {
const cache = await redis.get(`vertex:document:body:${url}`);
if (!cache) {
const res = (await util.requestPromise({
url: url,
headers: {
cookie: this.cookie
cookie: this.cookie,
...headers
}
}));
if (origin) return res.body;
Expand Down
5 changes: 1 addition & 4 deletions app/libs/rss.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ const _getRssContent = async function (rssUrl, suffix = true) {
const _getTorrents = async function (rssUrl) {
const rss = await parseXml(await _getRssContent(rssUrl));
const torrents = [];
let items = rss.rss.channel[0].item;
if (['chdbits', 'totheglory'].some(item => rssUrl.indexOf(item) !== -1)) {
items = items.slice(0, 5);
}
const items = rss.rss.channel[0].item;
for (let i = 0; i < items.length; ++i) {
const torrent = {
size: 0,
Expand Down
2 changes: 1 addition & 1 deletion app/libs/scrape.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const _freeMTeam = async function (url, cookie) {
const tid = url.match(/\/(\d+)/)[1];
// const host = new URL(url).host;
const { body } = await util.requestPromise({
url: 'https://kp.m-team.cc/api/torrent/detail',
url: 'https://api.m-team.cc/api/torrent/detail',
method: 'POST',
headers: {
'x-api-key': cookie
Expand Down
2 changes: 1 addition & 1 deletion app/libs/site/Audiences.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Site {
// 下载
info.leeching = +document.querySelector('img[class=arrowdown]').nextSibling.nodeValue.trim();
// 做种体积
const seedingDocument = await this._getDocument(`${this.index}getusertorrentlistajax.php?userid=${info.uid}&type=seeding`, true);
const seedingDocument = await this._getDocument(`${this.index}getusertorrentlistajax.php?userid=${info.uid}&type=seeding`, true, 300, false, { referer: `https://audiences.me/userdetails.php?id=${info.uid}` });
const seedingSize = (seedingDocument.match(/Total: (\d+\.\d+ [KMGTP]B)/) || [0, '0 B'])[1].replace(/([KMGTP])B/, '$1iB');
info.seedingSize = util.calSize(...seedingSize.split(' '));
return info;
Expand Down
5 changes: 2 additions & 3 deletions app/libs/site/MTeam.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const moment = require('moment');
const _api = async function (cookie, path, data, type = 'form') {
if (type === 'form') {
const { body } = await util.requestPromise({
url: `https://kp.m-team.cc${path}`,
url: `https://api.m-team.cc${path}`,
method: 'POST',
headers: {
'x-api-key': cookie
Expand All @@ -16,7 +16,7 @@ const _api = async function (cookie, path, data, type = 'form') {
}
if (type === 'json') {
const { body } = await util.requestPromise({
url: `https://kp.m-team.cc${path}`,
url: `https://api.m-team.cc${path}`,
method: 'POST',
headers: {
'x-api-key': cookie
Expand All @@ -31,7 +31,6 @@ const _api = async function (cookie, path, data, type = 'form') {
class Site {
constructor () {
this.name = 'MTeam';
this.downloadLink = 'https://kp.m-team.cc/download.php?id={ID}&https=1';
this.url = 'https://kp.m-team.cc/';
this.id = 3;
};
Expand Down
31 changes: 0 additions & 31 deletions app/model/SettingMod.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,37 +200,6 @@ class SettingMod {
});
}

async loginMTeam (options) {
const { body } = await util.requestPromise({
url: 'https://kp.m-team.cc/index.php',
headers: {
cookie: options.cookie
}
}, false);
const username = body.match(/userdetails.*?<b>(.*)<\/b>/);
if (username) {
return '无需登录 ' + username[1] + ' 使用已有 Cookie 即可';
}
if (body.indexOf('M-Team') === -1) {
throw new Error('疑似遇到 5s 盾, 请手动获取 Cookie 并重试');
}
const { headers } = await util.requestPromise({
url: 'https://kp.m-team.cc/verify.php?returnto=%2F',
method: 'POST',
headers: {
cookie: options.cookie
},
formData: {
otp: options.otp
}
}, false);
if (headers.location === 'https://kp.m-team.cc/') {
return '登录成功';
} else {
throw new Error('登录失败, 请重试');
}
}

async getTrackerFlowHistory () {
const _timeGroup = await util.getRecords('select time from tracker_flow where time >= ? group by time', [moment().unix() - 24 * 3600]);
const timeGroup = _timeGroup.map(i => i.time);
Expand Down
4 changes: 0 additions & 4 deletions app/model/UserMod.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,6 @@ class UserMod {
title: '网络测试',
path: '/tool/networkTest',
icon: ['fas', 'square-check']
}, {
title: 'MTEAM 登录',
path: '/tool/mteamLogin',
icon: ['fas', 'arrow-right-to-bracket']
}, {
title: '修改 HOSTS',
path: '/tool/hosts',
Expand Down
37 changes: 0 additions & 37 deletions app/script/loginMTeam.js

This file was deleted.

0 comments on commit eb0b2ed

Please sign in to comment.