Skip to content

Commit

Permalink
fix: yxdown missing cookies (DIYgod#10719)
Browse files Browse the repository at this point in the history
* fix: yxdown missing cookies

* refactor: migrate to v2

* fix: cookie parsing

* docs: fix attr
  • Loading branch information
linbuxiao authored Sep 6, 2022
1 parent 9ec2a9a commit 57b4669
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 20 deletions.
2 changes: 1 addition & 1 deletion docs/en/program-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Language

### BlueStacks 5 Release Notes

<RouteEn author="TonyRL" example="/bluestacks/release/5" path="/bluestacks/release/5" radar="1"/>
<RouteEn author="TonyRL" example="/bluestacks/release/5" path="/bluestacks/release/5" radar="1" puppeteer="1"/>

## Brave

Expand Down
2 changes: 1 addition & 1 deletion docs/program-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pageClass: routes

### BlueStacks 5 版本日誌

<Route author="TonyRL" example="/bluestacks/release/5" path="/bluestacks/release/5" radar="1"/>
<Route author="TonyRL" example="/bluestacks/release/5" path="/bluestacks/release/5" radar="1" puppeteer="1"/>

## Brave

Expand Down
4 changes: 2 additions & 2 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -3755,8 +3755,8 @@ router.get('/kingarthur/:type', lazyloadRouteHandler('./routes/kingarthur/index'
// router.get('/news/whxw', lazyloadRouteHandler('./routes/news/whxw'));

// 游讯网
router.get('/yxdown/recommend', lazyloadRouteHandler('./routes/yxdown/recommend'));
router.get('/yxdown/news/:category?', lazyloadRouteHandler('./routes/yxdown/news'));
// router.get('/yxdown/recommend', lazyloadRouteHandler('./routes/yxdown/recommend'));
// router.get('/yxdown/news/:category?', lazyloadRouteHandler('./routes/yxdown/news'));

// BabeHub
router.get('/babehub/search/:keyword?', lazyloadRouteHandler('./routes/babehub/search'));
Expand Down
4 changes: 4 additions & 0 deletions lib/v2/yxdown/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
'/news/:category?': ['nczitzk'],
'/recommend': ['nczitzk'],
};
19 changes: 11 additions & 8 deletions lib/routes/yxdown/news.js → lib/v2/yxdown/news.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
const { rootUrl, getCookie } = require('./utils');

module.exports = async (ctx) => {
const category = ctx.params.category ? `${ctx.params.category}/` : '';

const rootUrl = 'http://www.yxdown.com';
const currentUrl = `${rootUrl}/news/${category}`;

const response = await got({
method: 'get',
url: currentUrl,
});
const cookie = await getCookie();

const response = await got(currentUrl, {
headers: {
cookie,
},
});
const $ = cheerio.load(response.data);

const list = $('.div_zixun h2 a')
Expand All @@ -30,9 +32,10 @@ module.exports = async (ctx) => {
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
const detailResponse = await got(item.link, {
headers: {
cookie,
},
});
const content = cheerio.load(detailResponse.data);

Expand Down
19 changes: 19 additions & 0 deletions lib/v2/yxdown/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
'yxdown.com': {
_name: '游讯网',
'.': [
{
title: '资讯',
docs: 'https://docs.rsshub.app/game.html#you-xun-wang',
source: ['/news/:category', '/news'],
target: (params) => `/yxdown/news${params.category ? `/${params.category}` : ''}`,
},
{
title: '精彩推荐',
docs: 'https://docs.rsshub.app/game.html#you-xun-wang',
source: ['/'],
target: '/yxdown/recommend',
},
],
},
};
19 changes: 11 additions & 8 deletions lib/routes/yxdown/recommend.js → lib/v2/yxdown/recommend.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
const { rootUrl, getCookie } = require('./utils');

module.exports = async (ctx) => {
const rootUrl = 'http://www.yxdown.com';
const currentUrl = `${rootUrl}/news`;
const response = await got({
method: 'get',
url: currentUrl,
const currentUrl = `${rootUrl}/news/`;
const cookie = await getCookie();
const response = await got(currentUrl, {
headers: {
cookie,
},
});

const $ = cheerio.load(response.data);
Expand All @@ -27,9 +29,10 @@ module.exports = async (ctx) => {
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
const detailResponse = await got(item.link, {
headers: {
cookie,
},
});
const content = cheerio.load(detailResponse.data);

Expand Down
4 changes: 4 additions & 0 deletions lib/v2/yxdown/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = (router) => {
router.get('/news/:category?', require('./news'));
router.get('/recommend', require('./recommend'));
};
17 changes: 17 additions & 0 deletions lib/v2/yxdown/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const got = require('@/utils/got');

const rootUrl = 'http://www.yxdown.com';

const getCookie = async () => {
const cookieResponse = await got(rootUrl);

const cookieRegx = /(?<=.cookie=").*(?=; path)/g;
const cookieStr = cookieResponse.data.match(cookieRegx)[0];

return cookieStr;
};

module.exports = {
rootUrl,
getCookie,
};

0 comments on commit 57b4669

Please sign in to comment.