feat: add 电鸭社区 (#3453)

This commit is contained in:
陈玉祥
2019-11-21 11:06:43 +08:00
committed by DIYgod
parent 1d61677e76
commit 78baf39038
3 changed files with 46 additions and 0 deletions

View File

@@ -215,6 +215,11 @@ type 为 all 时category 参数不支持 cost 和 free
</Route>
## 电鸭社区
### 工作机会
<Route author="sfyumi" example="/eleduck/jobs" path="/eleduck/jobs"/>
## 福利资源-met.red
### 福利资源-met.red

View File

@@ -1783,6 +1783,9 @@ router.get('/mail/imap/:email', require('./routes/mail/imap'));
// 智联招聘
router.get('/zhilian/:city/:keyword', require('./routes/zhilian/index'));
// 电鸭社区
router.get('/eleduck/jobs', require('./routes/eleduck/jobs'));
// 北华航天工业学院 - 新闻
router.get('/nciae/news', require('./routes/universities/nciae/news'));

View File

@@ -0,0 +1,38 @@
const got = require('@/utils/got');
module.exports = async (ctx) => {
const response = await got({
method: 'get',
url: `https://svc.eleduck.com/api/v1/posts?category=5&page=1`,
});
const data = response.data.posts;
const out = await Promise.all(
data.map(async (job) => {
const url = `https://svc.eleduck.com/api/v1/posts/${job.id}`;
const cache = await ctx.cache.get(url);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const response = await got.get(url);
const jobDetail = response.data.post;
const single = {
title: jobDetail.title,
link: `https://eleduck.com/posts/${job.id}`,
author: jobDetail.user.nickname,
description: jobDetail.content.main,
pubDate: new Date(jobDetail.published_at).toUTCString(),
};
ctx.cache.set(url, JSON.stringify(single));
return Promise.resolve(single);
})
);
ctx.state.data = {
title: '电鸭社区-工作机会',
link: 'https://eleduck.com/?category=5',
item: out,
};
};