diff --git a/src/commands/fun/gelbooru.js b/src/commands/fun/gelbooru.js index ef14b72..4096b4e 100644 --- a/src/commands/fun/gelbooru.js +++ b/src/commands/fun/gelbooru.js @@ -1,4 +1,5 @@ const { InteractionContextType, ApplicationIntegrationType, SlashCommandBuilder, EmbedBuilder, escapeMarkdown, bold } = require("discord.js"); +const { generateImageUrl } = require('@imgproxy/imgproxy-node'); const { stringify } = require("node:querystring"); const { readFileSync } = require("node:fs"); const { decode } = require("html-entities"); @@ -105,6 +106,20 @@ function isAIPost(post) { var credentials = JSON.parse(readFileSync("credentials.json")); +function proxy(url) { + if (!process.env.IMGPROXY_HOST) + return url; + + url = generateImageUrl({ + endpoint: process.env.IMGPROXY_HOST, + url: url, + salt: process.env.IMGPROXY_SALT, + key: process.env.IMGPROXY_KEY + }); + + return url; +} + module.exports = { data, async execute(interaction) { @@ -156,7 +171,7 @@ module.exports = { .setTitle(`Post #${post.id}`) .setURL(post.postView) .setDescription(description) - .setImage(post.fileUrl) + .setImage(proxy(post.fileUrl)) .setFooter({ text: footerText, iconURL: `https://${post.booru.domain}/favicon.ico`,