* style: add eslint-unicorn * style: fix unicorn/no-useless-spread * style: fix unicorn/no-useless-promise-resolve-reject * style: fix unicorn/no-for-loop * fix: codeql bad HTML filtering regexp * fix: codeql incomplete replace * fix: unicorn/no-abusive-eslint-disable * style: fix unicorn/no-new-array * style: fix unicorn/no-typeof-undefined * style: fix unicorn/no-zero-fractions * style: fix unicorn/no-empty-file * style: fix unicorn/prefer-date-now * revert: auto fix unicorn/prefer-switch on lib/v2/kuaidi100/utils.js * style: fix unicorn/prefer-array-find * style: fix unicorn/prefer-array-flat * style: fix unicorn/prefer-array-flat-map * style: fix unicorn/prefer-at * style: fix unicorn/prefer-string-starts-ends-with * style: fix unicorn/prefer-includes * fix: codeql URL substring sanitization * style: fix unicorn/prefer-optional-catch-binding * style: fix unicorn/catch-error-name * style: fix unicorn/escape-case * style: fix unicorn/prefer-native-coercion-functions * style: fix unicorn/prefer-regexp-test * style: fix unicorn/require-array-join-separator * style: fix unicorn/prefer-math-trunc * style: fix unicorn/prefer-negative-index * style: fix unicorn/prefer-dom-node-dataset * style: fix unicorn/prefer-dom-node-text-content * style: fix unicorn/prefer-query-selector * style: fix unicorn/no-array-for-each * style: fix unicorn/no-negated-condition * style: fix unicorn/prefer-add-event-listener * style: fix unicorn/import-style * style: fix prefer-regex-literals * style: disable unicorn/no-useless-switch-case * style: disable unicorn/text-encoding-identifier-case * style: fix unicorn/prefer-set-has * style: fix unicorn/prefer-spread * revert: auto fix on lib/routes/universities/ynnu/edu/base64.js * style: fix unicorn/no-useless-undefined * style: fix unicorn/no-array-push-push * style: fix unicorn/no-useless-undefined again * style: fix unicorn/no-lonely-if * style: fix unicorn/prefer-reflect-apply * style: fix unicorn/switch-case-braces * style: fix unicorn/prefer-switch * style: fix unicorn/prefer-array-some * fix: deepscan UNUSED_VAR_ASSIGN * style: fix unicorn/prefer-ternary * fix: follow-up of unicorn/prefer-ternary * revert: auto fix of unicorn/prefer-string-slice for substring() * style: disable unicorn/prefer-string-slice fix: auto fix slice over deprecated substr * style: fix unicorn/throw-new-error * style: fix unicorn/filename-case * test: fix dateParser renaming * style: fix unicorn/better-regex * style: fix unicorn/prefer-string-replace-all * fix(deps): add sanitize-html * style: fix no-prototype-builtins * style: fix unicorn/consistent-destructuring * style: fix unicorn/consistent-function-scoping * style: fix unicorn/prefer-regexp-test * style: fix unicorn/prefer-logical-operator-over-ternary * style: fix unicorn/no-array-callback-reference * style: add prefer-object-has-own * style: warn unicorn/no-empty-file * style: fix unicorn/prefer-number-properties * style: fix no-useless-undefined again * style: fix unicorn/numeric-separators-style * style: disable unicorn/no-array-callback-reference false postive with cheerio
118 lines
4.1 KiB
JavaScript
118 lines
4.1 KiB
JavaScript
const got = require('@/utils/got');
|
|
const pediyUtils = require('./utils');
|
|
const cheerio = require('cheerio');
|
|
|
|
const baseUrl = 'https://bbs.pediy.com/';
|
|
const categoryId = {
|
|
iot: [128, '智能设备'],
|
|
blockchain: [172, '区块链安全'],
|
|
android: [161, 'Android安全'],
|
|
ios: [166, 'iOS安全'],
|
|
re: [4, '软件逆向'],
|
|
coding: [41, '编程技术'],
|
|
unpack: [88, '加壳脱壳'],
|
|
crypto: [132, '密码算法'],
|
|
vuln: [150, '二进制漏洞'],
|
|
crackme: [37, 'CrackMe'],
|
|
pwn: [171, 'Pwn'],
|
|
web: [151, 'WEB安全'],
|
|
translate: [32, '外文翻译'],
|
|
};
|
|
|
|
module.exports = async (ctx) => {
|
|
const category = ctx.params.category || 'all';
|
|
const type = ctx.params.type || 'latest';
|
|
let path;
|
|
let title;
|
|
if (Object.hasOwn(categoryId, category)) {
|
|
if (type === 'digest') {
|
|
// type为digest时只获取精华帖
|
|
path = `forum-${categoryId[category][0]}-1.htm?digest=1`;
|
|
title = `看雪论坛精华主题 - ${categoryId[category][1]}`;
|
|
} else {
|
|
// type为空/非法/latest时则只获取最新帖
|
|
path = `forum-${categoryId[category][0]}.html`;
|
|
title = `看雪论坛最新主题 - ${categoryId[category][1]}`;
|
|
}
|
|
} else {
|
|
// category未知时则获取全站最新帖
|
|
if (category === 'digest') {
|
|
path = 'new-digest.htm';
|
|
title = '看雪论坛精华主题';
|
|
} else {
|
|
path = 'new-tid.htm';
|
|
title = '看雪论坛最新主题';
|
|
}
|
|
}
|
|
|
|
const response = await got({
|
|
method: 'get',
|
|
url: baseUrl + path,
|
|
headers: {
|
|
Referer: baseUrl,
|
|
},
|
|
});
|
|
|
|
const $ = cheerio.load(response.data);
|
|
const list = $('.thread');
|
|
|
|
const resultItem = await Promise.all(
|
|
list
|
|
? list
|
|
// fix .thread .top_3
|
|
.filter((_, elem) => {
|
|
const pubDate = pediyUtils.dateParser($('.date', elem).eq(0).text(), 8);
|
|
return !elem.attribs.class.includes('top') || Date.now() - new Date(pubDate) < 1000 * 60 * 60 * 24 * 3;
|
|
})
|
|
.map(async (_, elem) => {
|
|
const subject = $('.subject a', elem).eq(1);
|
|
const pubDate = pediyUtils.dateParser($('.date', elem).eq(0).text(), 8);
|
|
|
|
const link = `${baseUrl}${subject.attr('href')}`;
|
|
const key = `pediy: ${link}`;
|
|
const value = await ctx.cache.get(key);
|
|
let description;
|
|
|
|
if (value) {
|
|
description = value;
|
|
} else {
|
|
const postDetail = await got({
|
|
method: 'get',
|
|
url: link,
|
|
});
|
|
const $ = cheerio.load(postDetail.data);
|
|
$('.card')
|
|
.eq(0)
|
|
.find('.message img')
|
|
.each((_, item) => {
|
|
item = $(item);
|
|
|
|
const src = item.attr('src');
|
|
if (src !== undefined && !src.startsWith('https://') && !src.startsWith('http://')) {
|
|
item.attr('src', `https://bbs.pediy.com/${src}`);
|
|
}
|
|
item.attr('referrerpolicy', 'no-referrer');
|
|
});
|
|
|
|
description = $('.card').eq(0).find('.message').html();
|
|
ctx.cache.set(key, description);
|
|
}
|
|
|
|
return {
|
|
title: subject.text(),
|
|
link,
|
|
pubDate: new Date(pubDate),
|
|
description,
|
|
};
|
|
})
|
|
.get()
|
|
: []
|
|
);
|
|
|
|
ctx.state.data = {
|
|
title,
|
|
link: baseUrl + path,
|
|
item: resultItem,
|
|
};
|
|
};
|