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