diff --git a/docs/bbs.md b/docs/bbs.md index 87e67c6651..8a5f050113 100644 --- a/docs/bbs.md +++ b/docs/bbs.md @@ -16,10 +16,20 @@ pageClass: routes ## Discuz -### 通用子版块 +### 通用子版块-自动检测 +### 通用子版块-指定版本 + + + +| Discuz X 系列 | Discuz 7.x 系列 | +| ------------- | --------------- | +| x | 7 | + + + ## MCBBS ### 版块 diff --git a/docs/en/bbs.md b/docs/en/bbs.md index 0bb45d43e3..1b6caa887e 100644 --- a/docs/en/bbs.md +++ b/docs/en/bbs.md @@ -3,3 +3,19 @@ pageClass: routes --- # BBS + +## Discuz + +### General Subforum - Auto detection + + + +### General Subforum - Manual version + + + +| Discuz X Series | Discuz 7.x Series | +| --------------- | ----------------- | +| x | 7 | + + diff --git a/lib/router.js b/lib/router.js index e0df2518b2..f9f7611fde 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2152,6 +2152,7 @@ router.get('/gbcc/trust', require('./routes/gbcc/trust')); router.get('/apnews/topics/:topic', require('./routes/apnews/topics')); // discuz +router.get('/discuz/:ver([7|x])/:link(.*)', require('./routes/discuz/discuz')); router.get('/discuz/:link(.*)', require('./routes/discuz/discuz')); // China Dialogue 中外对话 diff --git a/lib/routes/discuz/discuz.js b/lib/routes/discuz/discuz.js index 197f96182f..a14ec0c9a1 100644 --- a/lib/routes/discuz/discuz.js +++ b/lib/routes/discuz/discuz.js @@ -44,6 +44,7 @@ async function load(baseUrl, itemLink, ctx, charset) { module.exports = async (ctx) => { let link = ctx.params.link; + const ver = ctx.params.ver ? ctx.params.ver.toUpperCase() : undefined; link = link.replace(/:\/\//, ':/').replace(/:\//, '://'); const response = await got.get(link); @@ -52,18 +53,18 @@ module.exports = async (ctx) => { let charset = 'utf-8'; for (const attr of contentType.split(';')) { if (attr.indexOf('charset=') >= 0) { - charset = attr.split('=').pop(); + charset = attr + .split('=') + .pop() + .toLowerCase(); } } const responseData = charset === 'utf-8' ? response.data : iconv.decode((await got.get({ url: link, responseType: 'buffer' })).data, charset); const $ = cheerio.load(responseData); const title = $('head > title').text(); + const version = ver ? 'DISCUZ! ' + ver : $('head > meta[name=generator]').attr('content'); let process; - if ( - $('div#footer p em') - .text() - .startsWith('7') - ) { + if (version.toUpperCase().startsWith('DISCUZ! 7')) { // discuz 7.x 系列 // 支持全文抓取,限制抓取页面5个 const list = $('tbody[id^="normalthread"] tr') @@ -82,12 +83,7 @@ module.exports = async (ctx) => { return Promise.resolve(Object.assign({}, single, detail)); }) ); - } else if ( - $('div#frt p em') - .text() - .toUpperCase() - .startsWith('X') - ) { + } else if (version.toUpperCase().startsWith('DISCUZ! X')) { // discuz X 系列 // 支持全文抓取,限制抓取页面5个 const list = $('tbody[id^="normalthread"] tr')