mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-01 14:57:14 +08:00
fix(route): segment fault user (#12900)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
const { acw_sc__v2 } = require('./utils');
|
||||
const host = 'https://segmentfault.com';
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
@@ -19,10 +19,16 @@ module.exports = async (ctx) => {
|
||||
author,
|
||||
}));
|
||||
|
||||
const acwScV2Cookie = await acw_sc__v2(list[0].link, ctx.cache.tryGet);
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const response = await got(item.link);
|
||||
const response = await got(item.link, {
|
||||
headers: {
|
||||
cookie: `acw_sc__v2=${acwScV2Cookie};`,
|
||||
},
|
||||
});
|
||||
const content = cheerio.load(response.data);
|
||||
|
||||
item.description = content('article')
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
const zlib = require('zlib');
|
||||
const got = require('@/utils/got');
|
||||
const config = require('@/config').value;
|
||||
const { getAcwScV2ByArg1 } = require('@/v2/5eplay/utils');
|
||||
|
||||
const acw_sc__v2 = (link, tryGet) =>
|
||||
tryGet(
|
||||
'segmentfault:acw_sc__v2',
|
||||
async () => {
|
||||
const response = await got(link, {
|
||||
decompress: false,
|
||||
});
|
||||
|
||||
const unzipData = zlib.createUnzip();
|
||||
unzipData.write(response.body);
|
||||
|
||||
let acw_sc__v2 = '';
|
||||
for await (const data of unzipData) {
|
||||
const strData = data.toString();
|
||||
const matches = strData.match(/var arg1='(.*?)';/);
|
||||
if (matches) {
|
||||
acw_sc__v2 = getAcwScV2ByArg1(matches[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return acw_sc__v2;
|
||||
},
|
||||
config.cache.routeExpire,
|
||||
false
|
||||
);
|
||||
|
||||
module.exports = {
|
||||
acw_sc__v2,
|
||||
};
|
||||
Reference in New Issue
Block a user