Skip to content

Commit

Permalink
feat(route): add 少女前线新闻 & 公告 (DIYgod#6953)
Browse files Browse the repository at this point in the history
Co-authored-by: NeverBehave <[email protected]>
  • Loading branch information
Ethan Shen and NeverBehave authored Mar 2, 2021
1 parent 7320072 commit 11f7179
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/game.md
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,18 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的

<Route author="hoilc" example="/cowlevel/element/1370" path="/cowlevel/element/:id" :paramsDesc="['元素 ID, 可在 URL 中找到']" radar="1" rssbud="1"/>

## 少女前线

### 新闻

<Route author="nczitzk" example="/gf-cn/news" path="/gf-cn/news/:category?" :paramsDesc="['分类,见下表,默认为新闻']">

| 新闻 | 公告 |
| ---- | ---- |
| 1 | 3 |

</Route>

## 网易大神

### 用户发帖
Expand Down
4 changes: 4 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -3968,12 +3968,16 @@ router.get('/furaffinity/journal_comments/:id', require('./routes/furaffinity/jo

// Logseq
router.get('/logseq/changelog', require('./routes/logseq/changelog'));

// 亿欧网
router.get('/iyiou', require('./routes/iyiou'));

// 香港商报
router.get('/hkcd/pdf', require('./routes/hkcd/pdf'));

// 少女前线
router.get('/gf-cn/news/:category?', require('./routes/gf-cn/news'));

// Eagle
router.get('/eagle/changelog/:language?', require('./routes/eagle/changelog'));

Expand Down
40 changes: 40 additions & 0 deletions lib/routes/gf-cn/news.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const got = require('@/utils/got');

module.exports = async (ctx) => {
const category = ctx.params.category || '1';

const rootUrl = 'https://gfcn-webserver.sunborngame.com';
const currentUrl = `${rootUrl}/website/news_list/${category}?page=0&limit=11`;
const response = await got({
method: 'get',
url: currentUrl,
});

const list = response.data.data.list.map((item) => ({
title: item.Title,
link: `${rootUrl}/website/news/${item.Id}`,
pubDate: new Date(item.Date).toUTCString(),
}));

const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
item.description = detailResponse.data.data.Content;
item.link = item.link.replace(`${rootUrl}/website/news/`, `${rootUrl}/NewsInfo?id=`);

return item;
})
)
);

ctx.state.data = {
title: `少女前线 - ${category === '1' ? '新闻' : '公告'}`,
link: currentUrl,
item: items,
};
};

0 comments on commit 11f7179

Please sign in to comment.