From 3735788552ef98bc4e7e5ec6641677ad94fba1aa Mon Sep 17 00:00:00 2001 From: Jack Yu Date: Tue, 22 Oct 2019 16:17:15 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=201draw=EF=BC=8Creso?= =?UTF-8?q?lves=20#3304=20(#3310)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/anime.md | 7 +++++++ lib/router.js | 3 +++ lib/routes/1draw/index.js | 44 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 lib/routes/1draw/index.js diff --git a/docs/anime.md b/docs/anime.md index af3891b158..92cbfdbf68 100644 --- a/docs/anime.md +++ b/docs/anime.md @@ -9,6 +9,13 @@ pageClass: routes ### 二次元资讯 + +## 1draw #深夜の真剣お絵描き 60 分一本勝負 + +### 投稿一览 + + + ## Anime1 ### 動畫 diff --git a/lib/router.js b/lib/router.js index c233c6ddaf..21a2576825 100644 --- a/lib/router.js +++ b/lib/router.js @@ -27,6 +27,9 @@ router.get('/test/:id', require('./routes/test')); // RSSHub router.get('/rsshub/rss', require('./routes/rsshub/rss')); +// 1draw +router.get('/1draw/', require('./routes/1draw/index')); + // bilibili router.get('/bilibili/user/video/:uid', require('./routes/bilibili/video')); router.get('/bilibili/user/article/:uid', require('./routes/bilibili/article')); diff --git a/lib/routes/1draw/index.js b/lib/routes/1draw/index.js new file mode 100644 index 0000000000..4411e3e782 --- /dev/null +++ b/lib/routes/1draw/index.js @@ -0,0 +1,44 @@ +const got = require('@/utils/got'); + +function toJSONstr(content) { + // 使用了正则匹配 Javascript 数据,对字符串处理解析成 JSON,可能失效 + const dateRegex = /\[\];(?.*?)var/s; + return content + .match(dateRegex) + .groups.data.replace(/data\.push\(/gm, '') + .replace(/\);/gm, ',') + .replace(/(screen_name|id|allow|img):/gm, '"$1":'); +} + +module.exports = async (ctx) => { + const host = 'http://1draw.aqn.jp'; + + const response = await got(`${host}/1`); + const yesterday = response.data; + + let matches = toJSONstr(yesterday); + + // 东九区时间晚 10 点后尝试抓取今日 + if (new Date().getUTCHours() >= 13) { + const response = await got(`${host}/0`); + const today = response.data; + try { + matches += toJSONstr(today); + } catch (e) { + matches += ''; + } + } + + const matchArr = `[ ${matches.slice(0, matches.lastIndexOf(','))} ]`; + const items = JSON.parse(matchArr); + + ctx.state.data = { + title: '1draw', + link: 'http://1draw.aqn.jp/', + item: items.map((item) => ({ + title: `${item.screen_name}の投稿イラスト`, + description: ``, + link: `https://twitter.com/${item.screen_name}/status/${item.id}`, + })), + }; +};