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, + }; +};