fix(route): kemono image (#11998)
This commit is contained in:
parent
1474949bee
commit
8a1d9717a2
|
|
@ -1,6 +1,8 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const { art } = require('@/utils/render');
|
||||
const path = require('path');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const source = ctx.params.source ?? '';
|
||||
|
|
@ -26,29 +28,30 @@ module.exports = async (ctx) => {
|
|||
if (source === 'discord') {
|
||||
title = `Posts of ${id} from Discord | Kemono`;
|
||||
|
||||
await Promise.all(
|
||||
response.data.map(async (channel) => {
|
||||
await ctx.cache.tryGet(channel.id, async () => {
|
||||
items = await Promise.all(
|
||||
response.data.map((channel) =>
|
||||
ctx.cache.tryGet(channel.id, async () => {
|
||||
const channelResponse = await got({
|
||||
method: 'get',
|
||||
url: `${rootUrl}/api/discord/channel/${channel.id}?skip=0`,
|
||||
headers,
|
||||
});
|
||||
|
||||
items.push(
|
||||
...channelResponse.data
|
||||
.filter((i) => i.content || i.attachments)
|
||||
.map((i) => ({
|
||||
title: i.content,
|
||||
description: (i.content ? `<p>${i.content}</p>` : '') + (i.attachments ? i.attachments.map((a) => `<img src="${rootUrl}${a.path}">`).join('') : ''),
|
||||
author: i.author.username,
|
||||
pubDate: parseDate(i.published),
|
||||
category: channel.name,
|
||||
}))
|
||||
);
|
||||
});
|
||||
})
|
||||
return channelResponse.data
|
||||
.filter((i) => i.content || i.attachments)
|
||||
.map((i) => ({
|
||||
title: i.content,
|
||||
description: art(path.join(__dirname, 'templates', 'discord.art'), { i }),
|
||||
author: `${i.author.username}#${i.author.discriminator}`,
|
||||
pubDate: parseDate(i.published),
|
||||
category: channel.name,
|
||||
guid: `kemono:${source}:${i.server}:${i.channel}:${i.id}`,
|
||||
link: `https://discord.com/channels/${i.server}/${i.channel}/${i.id}`,
|
||||
}));
|
||||
})
|
||||
)
|
||||
);
|
||||
items = items.flat();
|
||||
} else {
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
|
|
@ -77,7 +80,8 @@ module.exports = async (ctx) => {
|
|||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
content('.post__thumbnail').each(function () {
|
||||
content(this).html(`<img src="${rootUrl}${content(this).find('.fileThumb').attr('href')}">`);
|
||||
const href = content(this).find('.fileThumb').attr('href');
|
||||
content(this).html(`<img src="${href.startsWith('http') ? href : rootUrl + href}">`);
|
||||
});
|
||||
|
||||
item.description = content('.post__body').html();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
{{ if i.content }}
|
||||
<p>{{ i.content }}</p>
|
||||
{{ /if }}
|
||||
|
||||
{{ if i.attachments }}
|
||||
{{ each i.attachments a }}
|
||||
<img src="{{ a.path }}">
|
||||
{{ /each }}
|
||||
{{ /if }}
|
||||
|
||||
{{ if i.embeds }}
|
||||
{{ each i.embeds e }}
|
||||
{{ if e.type === 'image' }}
|
||||
<img src="{{ e.thumbnail.proxy_url }}">
|
||||
{{ else if e.type === 'link' }}
|
||||
{{ if e.thumbnail }}
|
||||
<a href="{{ e.thumbnail.url }}"><img src="{{ e.thumbnail.proxy_url }}"></a>
|
||||
{{ /if }}
|
||||
<a href="{{ e.url }}">{{ e.title }}</a>{{ if e.description }}<p>{{ e.description }}</p>{{ /if }}
|
||||
{{ /if }}
|
||||
{{ /each }}
|
||||
{{ /if }}
|
||||
Loading…
Reference in New Issue