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.
- Loading branch information
Showing
4 changed files
with
108 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const { JSDOM } = require('jsdom'); | ||
const utils = require('./utils'); | ||
|
||
module.exports = async (ctx) => { | ||
const id = ctx.params.id; | ||
const type = ctx.params.type; | ||
const userResponse = await got({ | ||
method: 'get', | ||
url: `https://shankapi.ifeng.com/winter/ishare/getAccountInfo/${id}`, | ||
headers: { | ||
Referer: `https://ishare.ifeng.com/mediaShare/home/${id}/do`, | ||
}, | ||
}); | ||
const contentResponse = await got({ | ||
method: 'get', | ||
url: `https://shankapi.ifeng.com/winter/ishare/getShareListData/${id}/${type}/1`, | ||
headers: { | ||
Referer: `https://ishare.ifeng.com/mediaShare/home/${id}/do`, | ||
}, | ||
}); | ||
|
||
const userData = userResponse.data.data.data; | ||
const contentData = contentResponse.data.data; | ||
|
||
const mediaName = userData.weMediaName; | ||
const items = await Promise.all( | ||
(contentData || []).map(async (item) => { | ||
const link = `https://feng.ifeng.com/c/${item.id}`; | ||
const simple = { | ||
title: item.title, | ||
description: `<img src="${item.thumbnail}">${item.title}`, | ||
pubDate: new Date(Date.parse(item.newsTime.replace(/-/g, '/'))), | ||
author: mediaName, | ||
link: link, | ||
}; | ||
|
||
const details = await ctx.cache.tryGet(`ifeng:feng:${link}`, async () => { | ||
const response = await got.get(link); | ||
const $ = cheerio.load(response.data); | ||
if (type === 'doc') { | ||
const dom = new JSDOM(`<body><script>${$('#__INITIAL_STATE__').html()}</script></body>`, { | ||
runScripts: 'dangerously', | ||
}); | ||
const data = dom.window.allData; | ||
return { | ||
description: utils.extractDoc(data), | ||
}; | ||
} | ||
if (type === 'video') { | ||
return { | ||
description: `<img src="${item.thumbnail}"><br><video src="${$('meta[name=og\\:img_video]').attr('content')}">`, | ||
}; | ||
} | ||
return { | ||
description: $('meta[name=description]').attr('content'), | ||
}; | ||
}); | ||
return Promise.resolve(Object.assign({}, simple, details)); | ||
}) | ||
); | ||
|
||
ctx.state.data = { | ||
title: `大风号-${mediaName}-${type === 'doc' ? '文章' : '视频'}`, | ||
link: `https://feng.ifeng.com/author/${id}`, | ||
item: items, | ||
}; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const extractDoc = (data) => { | ||
if (data.docData.contentData.contentList) { | ||
return extractContent(data.docData.contentData.contentList); | ||
} | ||
if (data.docData.contentData.image) { | ||
return data.docData.contentData.image.map((item) => `<p><img src="${item.url}"><br>${item.description.replace(/\n/g, '<br>')}</p>`).join(''); | ||
} | ||
}; | ||
|
||
const extractContent = (data) => | ||
(data || []) | ||
.map((item) => { | ||
const type = item.type; | ||
if (type === 'video') { | ||
return `<video src="${item.data.mobileUrl}">`; | ||
} | ||
if (type === 'text') { | ||
return item.data; | ||
} | ||
return ''; | ||
}) | ||
.join('<br>'); | ||
|
||
module.exports = { | ||
extractDoc, | ||
}; |