Skip to content

Commit

Permalink
feat(route): 营地改版,换用新接口 (DIYgod#7464)
Browse files Browse the repository at this point in the history
Co-authored-by: auto-bot-ty <auto-bot-ty@git@com>
  • Loading branch information
auto-bot-ty and auto-bot-ty authored May 10, 2021
1 parent d5d81f8 commit 43cda0b
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/game.md
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,21 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的

</Route>


### 分区

<Route author="auto-bot-ty" example="/lfsyd/tag/17" path="/lfsyd/tag/:tag" :paramsDesc="['订阅分区类型']">

| 炉石传说 | 万智牌 | 游戏王 | 昆特牌 | 影之诗 | 符文之地传奇 | 阴阳师百闻牌 |
| :------: | :----: | :----: | :----: | :----: | :----------: | :----------: |
| 17 | 18 | 16 | 19 | 20 | 329 | 221 |

| 英雄联盟 | 电子游戏 | 桌面游戏 | 卡牌游戏 | 玩家杂谈 | 二次元 |
| :------: | :------: | :------: | :------: | :------: | :----: |
| 112 | 389 | 24 | 102 | 23 | 117 |

</Route>

## 米哈游

### 崩坏 2 - 游戏公告
Expand Down
1 change: 1 addition & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ router.get('/3dm/news', require('./routes/3dm/news_center'));

// 旅法师营地
router.get('/lfsyd/:typecode', require('./routes/lfsyd/index'));
router.get('/lfsyd/tag/:tag', require('./routes/lfsyd/tag'));

// 喜马拉雅
router.get('/ximalaya/album/:id/:all?', require('./routes/ximalaya/album'));
Expand Down
65 changes: 65 additions & 0 deletions lib/routes/lfsyd/tag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const got = require('@/utils/got');
const util = require('./utils');
const timezone = require('@/utils/timezone');
const parseDate = require('@/utils/parse-date');

module.exports = async (ctx) => {
const tag_id = ctx.params.tag;
const tag_list = {
17: '炉石传说',
18: '万智牌',
16: '游戏王',
19: '昆特牌',
20: '影之诗',
329: '符文之地传奇',
221: '阴阳师百闻牌',
112: '英雄联盟',
389: '电子游戏',
24: '桌面游戏',
102: '卡牌游戏',
23: '玩家杂谈',
117: '二次元',
};
const tag_name = tag_list[tag_id];
const rootUrl = 'https://www.iyingdi.com';
const tagUrl = 'https://api.iyingdi.com/web/feed/tag-content-list';
const form = {
page: 1,
size: 30,
tag_id: tag_id,
timestamp: '',
version: 0,
};

const response = await got({
method: 'post',
url: tagUrl,
headers: {
Host: 'api.iyingdi.com',
'Login-Token': 'nologin',
Origin: rootUrl,
Platform: 'pc',
Referer: `${rootUrl}/`,
},
form: util.getForm(form),
});
const list = response.data.list;
const tag_json = JSON.parse(list[0].feed.tag_json);

const articleList = list.map((item) => ({
title: item.feed.title,
pubDate: timezone(parseDate(item.feed.show_time * 1000), +8),
link: `${rootUrl}/tz/post/${item.feed.source_id}`,
guid: item.feed.title,
post_id: item.feed.source_id,
}));

const items = await Promise.all(articleList.map(async (item) => await util.ProcessFeed(ctx, item)));

ctx.state.data = {
title: `${!tag_name ? tag_json[0].tag : tag_name} - 旅法师营地 `,
link: `${rootUrl}/tz/tag/${tag_id}`,
description: `${!tag_name ? tag_json[0].tag : tag_name} - 旅法师营地 `,
item: items,
};
};
45 changes: 45 additions & 0 deletions lib/routes/lfsyd/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const got = require('@/utils/got');
const md5 = require('@/utils/md5');

const ProcessFeed = async (ctx, item) => {
const infoUrL = 'https://api.iyingdi.com/web/post/info';
const rootUrl = 'https://www.iyingdi.com';
const info_form = {
post_id: item.post_id,
timestamp: '',
};

const description = await ctx.cache.tryGet(item.link, async () => {
const response = await got({
method: 'post',
url: infoUrL,
headers: {
Host: 'api.iyingdi.com',
'Login-Token': 'nologin',
Origin: rootUrl,
Platform: 'pc',
Referer: `${rootUrl}/`,
},
form: getForm(info_form),
});
const content_body = JSON.parse(response.body);
return content_body.post.content;
});

item.description = description;
delete item.post_id;
return item;
};

const getForm = function (form) {
const key = 'b8d5b38577b8bb382b0c783b474b95f9';
form.key = key;
form.timestamp = Math.floor(new Date().getTime() / 1000);
form.sign = md5(new URLSearchParams(form).toString());
delete form.key;
return form;
};
module.exports = {
getForm,
ProcessFeed,
};

0 comments on commit 43cda0b

Please sign in to comment.