diff --git a/lib/v2/kemono/index.js b/lib/v2/kemono/index.js index b8268ffea..6fde65b55 100644 --- a/lib/v2/kemono/index.js +++ b/lib/v2/kemono/index.js @@ -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 ? `

${i.content}

` : '') + (i.attachments ? i.attachments.map((a) => ``).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(``); + const href = content(this).find('.fileThumb').attr('href'); + content(this).html(``); }); item.description = content('.post__body').html(); diff --git a/lib/v2/kemono/templates/discord.art b/lib/v2/kemono/templates/discord.art new file mode 100644 index 000000000..23550ae4a --- /dev/null +++ b/lib/v2/kemono/templates/discord.art @@ -0,0 +1,22 @@ +{{ if i.content }} +

{{ i.content }}

+{{ /if }} + +{{ if i.attachments }} + {{ each i.attachments a }} + + {{ /each }} +{{ /if }} + +{{ if i.embeds }} + {{ each i.embeds e }} + {{ if e.type === 'image' }} + + {{ else if e.type === 'link' }} + {{ if e.thumbnail }} + + {{ /if }} + {{ e.title }}{{ if e.description }}

{{ e.description }}

{{ /if }} + {{ /if }} + {{ /each }} +{{ /if }}