From 67380a6067c8fdd1e48a4e546084c4ce388c5339 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Sun, 8 Sep 2019 12:43:48 +0800 Subject: [PATCH] feat(/ps/trophy): remove auto update; sort items by pubTime; fix title text --- lib/routes/ps/trophy.js | 53 +++-------------------------------------- package.json | 1 - yarn.lock | 9 ------- 3 files changed, 3 insertions(+), 60 deletions(-) diff --git a/lib/routes/ps/trophy.js b/lib/routes/ps/trophy.js index 4ecd937f1b..05d419e99b 100644 --- a/lib/routes/ps/trophy.js +++ b/lib/routes/ps/trophy.js @@ -1,58 +1,9 @@ const got = require('@/utils/got'); -const logger = require('@/utils/logger'); -const wait = require('@/utils/wait'); const cheerio = require('cheerio'); -const toughCookie = require('tough-cookie'); module.exports = async (ctx) => { const id = ctx.params.id; - // get cookies and token - const cookieJar = new toughCookie.CookieJar(); - const tokenResponse = await got({ - method: 'get', - url: 'https://psnprofiles.com/', - cookieJar: cookieJar, - }); - const token = cheerio - .load(tokenResponse.data)('meta[name="csrf-token"]') - .attr('content'); - - // update profile - const updateResponse = await got({ - method: 'post', - url: 'https://psnprofiles.com/xhr/update', - headers: { - Referer: `https://psnprofiles.com/`, - 'x-csrf-token': token, - 'x-requested-with': 'XMLHttpRequest', - }, - form: true, - data: { - psnId: id, - 'g-recaptcha-response': '', - }, - cookieJar: cookieJar, - }); - if (updateResponse.data.match('In Queue')) { - for (let i = 0; i < 10; i++) { - // eslint-disable-next-line no-await-in-loop - const checkResponse = await got({ - method: 'get', - url: `https://psnprofiles.com/xhr/update/status?user=${id}`, - headers: { - Referer: `https://psnprofiles.com/`, - }, - }); - if (checkResponse.data.status.match('updated')) { - logger.info(`${id}'s PSN profile has been updated`); - break; - } - // eslint-disable-next-line no-await-in-loop - await wait(200); - } - } - const response = await got({ method: 'get', url: `https://psnprofiles.com/${id}?order=last-trophy`, @@ -103,7 +54,8 @@ module.exports = async (ctx) => { $('.page h3') .eq(0) .text() - .trim(), + .trim() + .replace(' Trophies', ''), description: `