From 22a8ef009984e142ee3c848f3714f1c36626d4e0 Mon Sep 17 00:00:00 2001 From: ztmzzz <41851415+ztmzzz@users.noreply.github.com> Date: Sun, 28 Nov 2021 07:32:34 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E6=8E=8C=E4=B8=8A=E8=8B=B1=E9=9B=84?= =?UTF-8?q?=E8=81=94=E7=9B=9F=E7=89=B9=E5=AE=9A=E7=94=A8=E6=88=B7=E7=9A=84?= =?UTF-8?q?=E6=96=87=E7=AB=A0=20(#8469)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: ztmzzz --- docs/game.md | 4 +++ lib/router.js | 1 + lib/routes/lolapp/article.js | 53 ++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 lib/routes/lolapp/article.js diff --git a/docs/game.md b/docs/game.md index f79343b12..ab5f3e202 100644 --- a/docs/game.md +++ b/docs/game.md @@ -729,6 +729,10 @@ Example:`https://www.iyingdi.com/tz/people/55547` ,id 是 `55547` +### 用户文章 + + + ## 最终幻想 14 ### 最终幻想 14 国服 diff --git a/lib/router.js b/lib/router.js index 1cc988798..daa24dde3 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1912,6 +1912,7 @@ router.get('/lol/newsindex/:type', lazyloadRouteHandler('./routes/lol/newsindex' // 掌上英雄联盟 router.get('/lolapp/recommend', lazyloadRouteHandler('./routes/lolapp/recommend')); +router.get('/lolapp/article/:uuid', lazyloadRouteHandler('./routes/lolapp/article')); // 左岸读书 router.get('/zreading', lazyloadRouteHandler('./routes/zreading/home')); diff --git a/lib/routes/lolapp/article.js b/lib/routes/lolapp/article.js new file mode 100644 index 000000000..3eff4f9fc --- /dev/null +++ b/lib/routes/lolapp/article.js @@ -0,0 +1,53 @@ +const got = require('@/utils/got'); +const { parseRelativeDate } = require('@/utils/parse-date'); +const { parseDate } = require('@/utils/parse-date'); +const dayjs = require('dayjs'); +module.exports = async (ctx) => { + const uuid = ctx.params.uuid; + const url = 'https://mlol.qt.qq.com/go/mlol_news/author_feeds?author_uuid=' + uuid; + const res = await got.get(url).json(); + const data = res.data.feedsInfo; + const name = data[0].feedNews.footer.source; + const newData = []; + let pubDate = []; + for (let i = 0; i < data.length; i++) { + newData[i] = data[i].feedNews.body; + newData[i].link = 'https://mlol.qt.qq.com/go/mlol_news/varcache_article?is_lqt=true&docid=' + newData[i].commentID; + pubDate[i] = getPublishedDate(newData[i].link); + } + pubDate = await Promise.all(pubDate); + for (let i = 0; i < data.length; i++) { + newData[i].pubDate = pubDate[i]; + } + ctx.state.data = { + title: `${name}的文章`, + link: String(url), + description: `${name}的文章`, + item: newData.map((item) => ({ + title: item.title, + description: ``, + link: item.link, + pubDate: item.pubDate, + })), + }; +}; + +async function getPublishedDate(url) { + const res = await got.get(url).text(); + const start = res.indexOf('createdStr') + 15; + const end = res.indexOf('"', start); + const date = res.substring(start, end); + let publishedDate; + if (date === '刚刚') { + publishedDate = dayjs(); + } else if (date.indexOf('前') > 0) { + // XX分钟/小时前 + publishedDate = parseRelativeDate(date); + } else if (date.indexOf('年') > 0) { + // YYYY年MM月DD日+MM月DD日 hh:mm + publishedDate = parseDate(date, ['YYYY年MM月DD日', 'MM月DD日 hh:mm']); + } else { + publishedDate = dayjs(); + } + return publishedDate; +}