diff --git a/docs/en/other.md b/docs/en/other.md index b3d2facafb..89d02861e0 100644 --- a/docs/en/other.md +++ b/docs/en/other.md @@ -177,3 +177,9 @@ Type | all | rec | + +## dcinside + +### board + + diff --git a/docs/other.md b/docs/other.md index 541f3a0493..a2640b4db2 100644 --- a/docs/other.md +++ b/docs/other.md @@ -686,3 +686,9 @@ type 为 all 时,category 参数不支持 cost 和 free ### はてな匿名ダイアリー - 人気記事アーカイブ + +## dcinside + +### board + + diff --git a/lib/router.js b/lib/router.js index 5488be3359..3438b70d4c 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2814,6 +2814,9 @@ router.get('/gov/caict/bps', require('./routes/gov/caict/bps')); router.get('/gov/caict/qwsj', require('./routes/gov/caict/qwsj')); router.get('/gov/caict/caictgd', require('./routes/gov/caict/caictgd')); +// dcinside +router.get('/dcinside/board/:id', require('./routes/dcinside/board')); + // 企鹅电竞 router.get('/egameqq/room/:id', require('./routes/tencent/egame/room')); diff --git a/lib/routes/dcinside/board.js b/lib/routes/dcinside/board.js new file mode 100644 index 0000000000..ecf97072e9 --- /dev/null +++ b/lib/routes/dcinside/board.js @@ -0,0 +1,66 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const url = require('url'); + +const domain = 'https://m.dcinside.com'; + +const headers = { + Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9', + 'Accept-Encoding': 'gzip, deflate, br', + 'Accept-Language': 'ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7', + 'Cache-Control': 'max-age=0', + Connection: 'keep-alive', + Host: 'm.dcinside.com', + 'Sec-Fetch-Dest': 'document', + 'Sec-Fetch-Mode': 'navigate', + 'Sec-Fetch-Site': 'none', + 'Sec-Fetch-User': '?1', + 'Upgrade-Insecure-Requests': '1', + 'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Mobile Safari/537.36', +}; + +async function getData(ctx, link) { + const { body } = await got.get(link, { headers }); + const $ = cheerio.load(body); + const { path } = url.parse(link); + const key = `dcinside${path}`; + + let result = await ctx.cache.get(key); + if (result) { + return result; + } + + result = { + title: $('head title').text().trim(), + pubDate: new Date($('body > div.container > div > div > section > div.gallview-tit-box > div > ul > li:nth-child(2)').text()), + link, + description: $('body > div.container > div > div > section > div.gall-thum-btm > div > div.thum-txt').html(), + }; + + ctx.cache.set(key, result); + return result; +} + +async function getItems(ctx, $) { + return Promise.all( + $('body > div > div > div > section > ul.gall-detail-lst > li:not([class]) > div > a.lt') + .toArray() + .map((row) => getData(ctx, row.attribs.href)) + ); +} + +module.exports = async (ctx) => { + const { id } = ctx.params; + const link = `${domain}/board/${id}`; + + const { body } = await got.get(link, { headers }); + const $ = cheerio.load(body); + const rss = { + title: $('head title').text(), + description: $('head title').text(), + link, + item: await getItems(ctx, $), + }; + rss.item = rss.item.sort((a, b) => b.pubDate - a.pubDate); + ctx.state.data = rss; +};