mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
feat: request updating psn profile for /ps/trophy
This commit is contained in:
@@ -1,9 +1,58 @@
|
||||
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`,
|
||||
|
||||
@@ -88,6 +88,7 @@
|
||||
"sanitize-html": "1.20.1",
|
||||
"sharp": "0.23.0",
|
||||
"socks-proxy-agent": "4.0.2",
|
||||
"tough-cookie": "3.0.1",
|
||||
"tunnel": "0.0.6",
|
||||
"twit": "2.2.11",
|
||||
"winston": "3.2.1"
|
||||
|
||||
@@ -10289,6 +10289,15 @@ touch@^3.1.0:
|
||||
dependencies:
|
||||
nopt "~1.0.10"
|
||||
|
||||
tough-cookie@3.0.1:
|
||||
version "3.0.1"
|
||||
resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-3.0.1.tgz#9df4f57e739c26930a018184887f4adb7dca73b2"
|
||||
integrity sha512-yQyJ0u4pZsv9D4clxO69OEjLWYw+jbgspjTue4lTQZLfV0c5l1VmK2y1JK8E9ahdpltPOaAThPcp5nKPUgSnsg==
|
||||
dependencies:
|
||||
ip-regex "^2.1.0"
|
||||
psl "^1.1.28"
|
||||
punycode "^2.1.1"
|
||||
|
||||
tough-cookie@^2.3.3, tough-cookie@^2.3.4, tough-cookie@~2.5.0:
|
||||
version "2.5.0"
|
||||
resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.5.0.tgz#cd9fb2a0aa1d5a12b473bd9fb96fa3dcff65ade2"
|
||||
|
||||
Reference in New Issue
Block a user