From 5701b5f15f517f84ea6d1c7bc948748f79385e8f Mon Sep 17 00:00:00 2001 From: MythEclipse Date: Sat, 6 Jun 2026 14:13:18 +0700 Subject: [PATCH] feat(ai-moderation): use cached sticker image URLs directly instead of re-uploading base64 data --- .../ai-moderation/llmModerationClient.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/services/discord-gateway/src/modules/ai-moderation/llmModerationClient.ts b/services/discord-gateway/src/modules/ai-moderation/llmModerationClient.ts index 3141656..a56c854 100644 --- a/services/discord-gateway/src/modules/ai-moderation/llmModerationClient.ts +++ b/services/discord-gateway/src/modules/ai-moderation/llmModerationClient.ts @@ -21,7 +21,7 @@ import { getStickerFromCache, initStickerCache, isStickerCacheReady, - setStickerInCache, + uploadAndCacheSticker, } from "./stickerCache.js"; import { buildCustomEmojiVisionPrompt, @@ -1537,9 +1537,8 @@ async function _runSingleMediaAnalysis( if (cached) { const part: MessageImagePart = { type: "image_url", - image_url: { - url: `data:${cached.mimeType};base64,${cached.base64}`, - }, + // imageUrl is already a remote URL — faster than re-uploading + image_url: { url: cached.imageUrl }, sourceLabel: candidate.label, stickerName: candidate.stickerName, }; @@ -1587,10 +1586,16 @@ async function _runSingleMediaAnalysis( await resizeImageForVision(result.data, maxDimension); const base64 = resizedBuffer.toString("base64"); + + // Upload sticker to external service and cache the URL (fire-and-forget). + // The current vision call still uses a data URL to avoid waiting on upload, + // but all subsequent occurrences will reuse the uploaded URL directly. if (candidate.stickerName) { - setStickerInCache(candidate.stickerName, base64, resizedMime).catch( - () => {}, - ); + uploadAndCacheSticker( + candidate.stickerName, + resizedBuffer, + resizedMime, + ).catch(() => {}); } const part: MessageImagePart = {