feat: 添加 1draw,resolves #3304 (#3310)

This commit is contained in:
Jack Yu
2019-10-22 16:17:15 +08:00
committed by DIYgod
parent 51db420832
commit 3735788552
3 changed files with 54 additions and 0 deletions
+7
View File
@@ -9,6 +9,13 @@ pageClass: routes
### 二次元资讯
<Route author="junfengP" example="/005tv/zx/latest" path="/005tv/zx/latest"/>
## 1draw #深夜の真剣お絵描き 60 分一本勝負
### 投稿一览
<Route author="jackyu1996" path="/1draw/" example="/1draw/" />
## Anime1
### 動畫
+3
View File
@@ -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'));
+44
View File
@@ -0,0 +1,44 @@
const got = require('@/utils/got');
function toJSONstr(content) {
// 使用了正则匹配 Javascript 数据,对字符串处理解析成 JSON,可能失效
const dateRegex = /\[\];(?<data>.*?)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: `<img src="${item.img}">`,
link: `https://twitter.com/${item.screen_name}/status/${item.id}`,
})),
};
};