fix(route): add cookie to nga forum route (#7174)

Co-authored-by: Haodong Du <duhd1993@gmail.com>
This commit is contained in:
Haodong DU 2021-03-26 17:54:50 -04:00 committed by GitHub
parent 1edc3b7076
commit 9ad88e6cf0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 0 deletions

View File

@ -1,7 +1,13 @@
const got = require('@/utils/got');
const config = require('@/config').value;
module.exports = async (ctx) => {
const { fid, recommend } = ctx.params;
const timestamp = Math.floor(Date.now() / 1000);
let cookieString = `guestJs=${timestamp};`;
if (config.nga.uid && config.nga.cid) {
cookieString = `ngaPassportUid=${config.nga.uid}; ngaPassportCid=${config.nga.cid};`;
}
const formatContent = (content) =>
content
.replace(/\[img\](.+?)\[\/img\]/g, (match, p1) => {
@ -14,6 +20,7 @@ module.exports = async (ctx) => {
url: 'https://ngabbs.com/app_api.php?__lib=subject&__act=list',
headers: {
'X-User-Agent': 'NGA_skull/6.0.5(iPhone10,3;iOS 12.0.1)',
Cookie: cookieString,
},
form: {
fid,
@ -41,6 +48,7 @@ module.exports = async (ctx) => {
url: 'https://ngabbs.com/app_api.php?__lib=post&__act=list',
headers: {
'X-User-Agent': 'NGA_skull/6.0.5(iPhone10,3;iOS 12.0.1)',
Cookie: cookieString,
},
form: {
tid,