From eb0b2edeec1e6ec15d618dc9f3a643cac786cf64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=B1=B1=E6=9C=AA=E6=9D=A5?= Date: Sat, 22 Jun 2024 00:27:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20MT=20api=20=E5=8F=98=E6=9B=B4=20#58?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/Site.js | 5 +++-- app/libs/rss.js | 5 +---- app/libs/scrape.js | 2 +- app/libs/site/Audiences.js | 2 +- app/libs/site/MTeam.js | 5 ++--- app/model/SettingMod.js | 31 ------------------------------- app/model/UserMod.js | 4 ---- app/script/loginMTeam.js | 37 ------------------------------------- 8 files changed, 8 insertions(+), 83 deletions(-) delete mode 100755 app/script/loginMTeam.js diff --git a/app/common/Site.js b/app/common/Site.js index ee7ba83c..12409c16 100644 --- a/app/common/Site.js +++ b/app/common/Site.js @@ -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; diff --git a/app/libs/rss.js b/app/libs/rss.js index 34da6b29..4eaa3b69 100644 --- a/app/libs/rss.js +++ b/app/libs/rss.js @@ -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, diff --git a/app/libs/scrape.js b/app/libs/scrape.js index 03b3eb6c..a12d2c57 100644 --- a/app/libs/scrape.js +++ b/app/libs/scrape.js @@ -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 diff --git a/app/libs/site/Audiences.js b/app/libs/site/Audiences.js index c1d0c63b..72907da3 100644 --- a/app/libs/site/Audiences.js +++ b/app/libs/site/Audiences.js @@ -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; diff --git a/app/libs/site/MTeam.js b/app/libs/site/MTeam.js index 534a3614..1e4b004b 100644 --- a/app/libs/site/MTeam.js +++ b/app/libs/site/MTeam.js @@ -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 @@ -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 @@ -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; }; diff --git a/app/model/SettingMod.js b/app/model/SettingMod.js index 096d41cd..43d984e1 100644 --- a/app/model/SettingMod.js +++ b/app/model/SettingMod.js @@ -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>/); - 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); diff --git a/app/model/UserMod.js b/app/model/UserMod.js index b78589fd..6ffd7a0d 100644 --- a/app/model/UserMod.js +++ b/app/model/UserMod.js @@ -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', diff --git a/app/script/loginMTeam.js b/app/script/loginMTeam.js deleted file mode 100755 index 9c881e7c..00000000 --- a/app/script/loginMTeam.js +++ /dev/null @@ -1,37 +0,0 @@ -const request = require('util').promisify(require('request')); - -(async () => { - const { body } = await request({ - url: 'https://kp.m-team.cc/index.php', - method: 'GET', - headers: { - cookie: process.argv[3], - 'user-agent': process.argv[2] - } - }); - const username = body.match(/userdetails.*?(.*)<\/b>/); - if (username) { - console.log('无需登录', username[1], '使用已有 Cookie 即可'); - return; - } - if (body.indexOf('M-Team') === -1) { - console.log('疑似遇到 5s 盾, 请手动获取 Cookie 并重试.'); - return; - } - const { headers } = await request({ - url: 'https://kp.m-team.cc/verify.php?returnto=%2F', - method: 'POST', - headers: { - cookie: process.argv[3], - 'user-agent': process.argv[2] - }, - formData: { - otp: process.argv[4] - } - }); - if (headers.location === 'https://kp.m-team.cc/') { - console.log('登录成功'); - } else { - console.log('登录失败, 请重试'); - } -})();