feat: support instagram sidecar
This commit is contained in:
parent
3390a3a66b
commit
9a730ccf0d
|
|
@ -18,11 +18,37 @@ module.exports = async (ctx) => {
|
|||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
// 获取组图
|
||||
const images = await Promise.all(
|
||||
list.map(async (item) => {
|
||||
item = item.node;
|
||||
if (item.__typename === 'GraphSidecar') {
|
||||
const url = `https://www.instagram.com/p/${item.shortcode}`;
|
||||
|
||||
const cache = await ctx.cache.get(url);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
const response = await axios({
|
||||
method: 'get',
|
||||
url,
|
||||
});
|
||||
const data = JSON.parse(response.data.match(/<script type="text\/javascript">window._sharedData = (.*);<\/script>/)[1]) || {};
|
||||
const single = data.entry_data.PostPage[0].graphql.shortcode_media.edge_sidecar_to_children.edges.map((item) => item.node.display_url);
|
||||
|
||||
ctx.cache.set(url, JSON.stringify(single), 24 * 60 * 60);
|
||||
return Promise.resolve(single);
|
||||
} else {
|
||||
return Promise.resolve([item.display_url]);
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${name}(@${id}) 的 Instagram`,
|
||||
link: `https://www.instagram.com/${id}/`,
|
||||
description: $('meta[name="description"]').attr('content'),
|
||||
item: list.map((item) => {
|
||||
item: list.map((item, index) => {
|
||||
item = item.node;
|
||||
let type = '';
|
||||
let tip = '';
|
||||
|
|
@ -33,12 +59,15 @@ module.exports = async (ctx) => {
|
|||
break;
|
||||
case 'GraphSidecar':
|
||||
type = '[组图] ';
|
||||
tip = '打开原文查看组图: ';
|
||||
break;
|
||||
}
|
||||
let imgTPL = '';
|
||||
for (let i = 0; i < images[index].length; i++) {
|
||||
imgTPL += `<img referrerpolicy="no-referrer" src="${images[index][i]}"><br>`;
|
||||
}
|
||||
return {
|
||||
title: `${type}${(item.edge_media_to_caption.edges && item.edge_media_to_caption.edges[0] && item.edge_media_to_caption.edges[0].node.text) || '无题'}`,
|
||||
description: `${tip}<img referrerpolicy="no-referrer" src="${item.display_url}">`,
|
||||
description: `${tip}${imgTPL}`,
|
||||
pubDate: new Date(item.taken_at_timestamp * 1000).toUTCString(),
|
||||
link: `https://www.instagram.com/p/${item.shortcode}/`,
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue