From 897e567523eb144653466ecfa7ff2c3c2c4a2827 Mon Sep 17 00:00:00 2001 From: junbaor Date: Thu, 25 Jul 2019 11:26:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=20Artand=20=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=96=B0=E4=BD=9C=E5=93=81=20(#2680)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 优化"王垠的博客-当然我在扯淡" * 删除文章数量参数 * feat: 新增 Artand 用户新作品 --- docs/shopping.md | 6 +++++ lib/router.js | 3 +++ lib/routes/artand/user/work.js | 42 ++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 lib/routes/artand/user/work.js diff --git a/docs/shopping.md b/docs/shopping.md index 0ecf80ef8..5bd61f7e6 100644 --- a/docs/shopping.md +++ b/docs/shopping.md @@ -159,3 +159,9 @@ pageClass: routes ### 小米有品每日上新 + +## Artand + +### 用户新作 + + diff --git a/lib/router.js b/lib/router.js index 7971bc588..6cb7289de 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1553,4 +1553,7 @@ router.get('/wikihow/category/:category/:type', require('./routes/wikihow/catego router.get('/getitfree/category/:category?', require('./routes/getitfree/category.js')); router.get('/getitfree/search/:keyword?', require('./routes/getitfree/search.js')); +// Artand +router.get('/artand/user/work/:uid', require('./routes/artand/user/work')); + module.exports = router; diff --git a/lib/routes/artand/user/work.js b/lib/routes/artand/user/work.js new file mode 100644 index 000000000..44ed3f81e --- /dev/null +++ b/lib/routes/artand/user/work.js @@ -0,0 +1,42 @@ +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + const uid = ctx.params.uid; + + const url = `https://ios2.artand.cn/user1/index?tab=work&uid=${uid}`; + const response = await got({ method: 'get', url }); + const dataUser = response.data.user; + const dataList = response.data.list; + + const result = await Promise.all( + dataList.map(async (item) => { + const voItem = { + title: item.name, + author: dataUser.uname, + description: '', + pubDate: new Date(item.mtime * 1000).toUTCString(), + link: `https://artand.cn/artid/${Number(item.id) + 100000}`, // +100000 的逻辑挺奇怪 + }; + + const link = 'https://ios2.artand.cn/works/index?post_id=' + item.id; + + const cache = await ctx.cache.get(link); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const itemReponse = await got.get(link); + voItem.description = itemReponse.data.data.work.desc; + + ctx.cache.set(link, JSON.stringify(voItem)); + return Promise.resolve(voItem); + }) + ); + + ctx.state.data = { + title: `${dataUser.uname} 的 Artand 新作`, + link: `https://artand.cn/${dataUser.uid}`, + description: `${dataUser.uname} 的 Artand 新作`, + item: result, + }; +};