diff --git a/package.json b/package.json index 8e4217e..3704813 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "author": "", "license": "MIT", "dependencies": { + "@imgproxy/imgproxy-node": "^1.0.6", "booru": "^2.6.8", "discord.js": "^14.16.3", "dotenv": "^16.4.5", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4c21828..e2ab526 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,9 @@ importers: .: dependencies: + '@imgproxy/imgproxy-node': + specifier: ^1.0.6 + version: 1.0.6 booru: specifier: ^2.6.8 version: 2.6.8 @@ -57,6 +60,12 @@ packages: resolution: {integrity: sha512-PZ+vLpxGCRtmr2RMkqh8Zp+BenUaJqlS6xhgWKEZcgC/vfHLEzpHtKkB0sl3nZWpwtcKk6YWy+pU3okL2I97FA==} engines: {node: '>=16.11.0'} + '@imgproxy/imgproxy-js-core@1.0.8': + resolution: {integrity: sha512-3oBneumj7b/YCeyLteKyKaidQSrDhEHnZMiVBHO0Hshju/YSplbzSeACZGwai7LyD3YMMpsK/kLIodXU6wbtMw==} + + '@imgproxy/imgproxy-node@1.0.6': + resolution: {integrity: sha512-Evdg3Ywry4RzIKTtQnHO3KsSKHa000GcdY4nRM2JRNdAgATv7fBD82nj6qzTgcqxpqcywnT1Sd2XGxxVg7ZC+w==} + '@sapphire/async-queue@1.5.3': resolution: {integrity: sha512-x7zadcfJGxFka1Q3f8gCts1F0xMwCKbZweM85xECGI0hBTeIZJGGCrHgLggihBoprlQ/hBmDR5LKfIPqnmHM3w==} engines: {node: '>=v14.0.0', npm: '>=7.0.0'} @@ -287,6 +296,12 @@ snapshots: - bufferutil - utf-8-validate + '@imgproxy/imgproxy-js-core@1.0.8': {} + + '@imgproxy/imgproxy-node@1.0.6': + dependencies: + '@imgproxy/imgproxy-js-core': 1.0.8 + '@sapphire/async-queue@1.5.3': {} '@sapphire/shapeshift@4.0.0': diff --git a/src/commands/fun/imagesearch.js b/src/commands/fun/imagesearch.js index 0cb0808..24e4f4a 100644 --- a/src/commands/fun/imagesearch.js +++ b/src/commands/fun/imagesearch.js @@ -1,6 +1,7 @@ const { InteractionContextType, ApplicationIntegrationType, SlashCommandBuilder, EmbedBuilder, escapeMarkdown, bold, ButtonBuilder, ButtonStyle } = require("discord.js"); -const { Pagination } = require('pagination.djs'); +const { generateImageUrl } = require('@imgproxy/imgproxy-node'); const { stringify } = require("node:querystring"); +const { Pagination } = require('pagination.djs'); const data = new SlashCommandBuilder() .setName("isrch") @@ -25,6 +26,20 @@ function notEmpty(str) { return str.trim() !== '' } +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) { @@ -49,7 +64,7 @@ module.exports = { const embed = new EmbedBuilder() .setColor("#cba6f7") - .setImage(result.img_src) + .setImage(proxy(result.img_src)) .setFooter({ text: result.engine });