forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix 'npm run format' and route '/metred/fuli' (DIYgod#6703) (DIYgod#6720
) * fix 'npm run format' * fix route '/metred/fuli' (DIYgod#6703) replace web crawling + cheerio with direct api access
- Loading branch information
1 parent
f1eedb0
commit 61fc6af
Showing
7 changed files
with
82 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,8 @@ | |
}, | ||
"env": { | ||
"node": true, | ||
"es6": true | ||
"es6": true, | ||
"browser": true | ||
}, | ||
"rules": { | ||
"no-console": 2, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,42 @@ | ||
const got = require('@/utils/got'); | ||
const host = 'https://met.red'; | ||
const mainPage = 'https://met.red/h/weal/list#'; | ||
const cheerio = require('cheerio'); | ||
const url = require('url'); | ||
|
||
async function load(link, ctx) { | ||
const cache = await ctx.cache.get(link); | ||
async function getItemDetail(itemId, ctx) { | ||
const link = `https://met.red/api/h/weal/getSingleDetail?wealId=${itemId}`; | ||
|
||
const cache = ctx.cache.get(link); | ||
if (cache) { | ||
return cache; | ||
} | ||
const response = await got.get(link); | ||
const $ = cheerio.load(response.data); | ||
const images = $('img'); | ||
for (let k = 0; k < images.length; k++) { | ||
$(images[k]).replaceWith(`<img src="${url.resolve(host, $(images[k]).attr('src'))}" />`); | ||
} | ||
const couponUrl = $('.layui-btn.layui-btn.layui-btn-lg').attr('href'); | ||
|
||
const eventHtml = couponUrl ? '<div><p>活动链接:无</p></div>' : `<div><a href="${couponUrl}">点我前往活动</a></div>`; | ||
const { data: response } = await got.get(link); | ||
const image = `<div><img src=${response.data.imgUrl} /></div>`; | ||
const coupon = response.data.url ? `<div><a href='${response.data.url}'>点击前往活动</a></div>` : ''; | ||
const content = image + coupon + response.data.content; | ||
|
||
ctx.cache.set(link, content); | ||
|
||
const description = eventHtml + $('.p-detail-html').html(); | ||
ctx.cache.set(link, description); | ||
return { description }; | ||
return content; | ||
} | ||
|
||
async function getItemList() { | ||
const response = await got('https://met.red/api/h/weal/getListForData'); | ||
return response.data.data; | ||
} | ||
|
||
module.exports = async (ctx) => { | ||
const response = await got({ | ||
method: 'get', | ||
url: mainPage, | ||
}); | ||
const data = response.data; | ||
const $ = cheerio.load(data); | ||
const list = $('h4 > a').get(); | ||
const process = await Promise.all( | ||
list.map(async (item) => { | ||
const itemUrl = host + $(item).attr('href'); | ||
const single = { | ||
title: $(item).text(), | ||
link: itemUrl, | ||
guid: itemUrl, | ||
}; | ||
const other = await load(itemUrl, ctx); | ||
return Promise.resolve(Object.assign({}, single, other)); | ||
}) | ||
); | ||
const itemList = await getItemList(); | ||
|
||
ctx.state.data = { | ||
title: '福利资源-met.red', | ||
link: mainPage, | ||
url: 'https://met.red/h/weal/list', | ||
description: '福利资源更新提醒', | ||
item: process, | ||
item: await Promise.all( | ||
itemList.map(async (item) => ({ | ||
title: item.name, | ||
link: `https://met.red/h/weal/detail/${item.id}`, | ||
description: await getItemDetail(item.id, ctx), | ||
guid: item.id, | ||
})) | ||
), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters