diff --git a/lib/router.js b/lib/router.js index 4acc8ca77..73dc2b2e8 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1010,7 +1010,7 @@ router.get('/project-zero-issues', lazyloadRouteHandler('./routes/project-zero-i router.get('/galaxylab', lazyloadRouteHandler('./routes/galaxylab/index')); // NOSEC 安全讯息平台 -router.get('/nosec/:keykind?', lazyloadRouteHandler('./routes/nosec/index')); +// router.get('/nosec/:keykind?', lazyloadRouteHandler('./routes/nosec/index')); // discuz // router.get('/discuz/:ver([7|x])/:cid([0-9]{2})/:link(.*)', lazyloadRouteHandler('./routes/discuz/discuz')); diff --git a/lib/routes-deprecated/nosec/index.js b/lib/routes/nosec/index.ts similarity index 72% rename from lib/routes-deprecated/nosec/index.js rename to lib/routes/nosec/index.ts index 5246dc6a8..8c8bd9eff 100644 --- a/lib/routes-deprecated/nosec/index.js +++ b/lib/routes/nosec/index.ts @@ -1,5 +1,6 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import { Route } from '@/types'; +import got from '@/utils/got'; +import { load } from 'cheerio'; const baseUrl = 'https://nosec.org/home/ajaxindexdata'; const keykinds = { @@ -12,15 +13,34 @@ const keykinds = { tool: '安全工具', }; -module.exports = async (ctx) => { +export const route: Route = { + path: '/:keykind?', + categories: ['programming'], + example: '/nosec/hole', + parameters: { keykind: '对应文章分类' }, + name: 'Posts', + maintainers: ['hellodword'], + description: ` | 分类 | 标识 | + | :------- | :--------- | + | 威胁情报 | \`threaten\` | + | 安全动态 | \`security\` | + | 漏洞预警 | \`hole\` | + | 数据泄露 | \`leakage\` | + | 专题报告 | \`speech\` | + | 技术分析 | \`skill\` | + | 安全工具 | \`tool\` |`, + handler, +}; + +async function handler(ctx) { const csrfresponse = await got.get('https://nosec.org/home/index'); - const $ = cheerio.load(csrfresponse.data); + const $ = load(csrfresponse.data); const token = $('meta[name="csrf-token"]').attr('content'); const cookies = csrfresponse.headers['set-cookie'].toString(); const xsrf_token = cookies.match(/XSRF-TOKEN=[^\s;]+/)[0]; const laravel_session = cookies.match(/laravel_session[^\s;]+/)[0]; - const keykind = ctx.params.keykind || ''; + const keykind = ctx.req.param('keykind') || ''; let formdata; let title; let link; @@ -50,7 +70,7 @@ module.exports = async (ctx) => { const data = response.data.data.threatData.data; - ctx.state.data = { + return { // 源标题 title, // 源链接 @@ -70,4 +90,4 @@ module.exports = async (ctx) => { author: item.username, })), }; -}; +}; \ No newline at end of file diff --git a/lib/routes/nosec/namespace.ts b/lib/routes/nosec/namespace.ts new file mode 100644 index 000000000..1a78a3c8e --- /dev/null +++ b/lib/routes/nosec/namespace.ts @@ -0,0 +1,6 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'NOSEC.org', + url: 'nosec.org', +};