feat(ai-moderation): use cached sticker image URLs directly instead of re-uploading base64 data
This commit is contained in:
@@ -21,7 +21,7 @@ import {
|
|||||||
getStickerFromCache,
|
getStickerFromCache,
|
||||||
initStickerCache,
|
initStickerCache,
|
||||||
isStickerCacheReady,
|
isStickerCacheReady,
|
||||||
setStickerInCache,
|
uploadAndCacheSticker,
|
||||||
} from "./stickerCache.js";
|
} from "./stickerCache.js";
|
||||||
import {
|
import {
|
||||||
buildCustomEmojiVisionPrompt,
|
buildCustomEmojiVisionPrompt,
|
||||||
@@ -1537,9 +1537,8 @@ async function _runSingleMediaAnalysis(
|
|||||||
if (cached) {
|
if (cached) {
|
||||||
const part: MessageImagePart = {
|
const part: MessageImagePart = {
|
||||||
type: "image_url",
|
type: "image_url",
|
||||||
image_url: {
|
// imageUrl is already a remote URL — faster than re-uploading
|
||||||
url: `data:${cached.mimeType};base64,${cached.base64}`,
|
image_url: { url: cached.imageUrl },
|
||||||
},
|
|
||||||
sourceLabel: candidate.label,
|
sourceLabel: candidate.label,
|
||||||
stickerName: candidate.stickerName,
|
stickerName: candidate.stickerName,
|
||||||
};
|
};
|
||||||
@@ -1587,10 +1586,16 @@ async function _runSingleMediaAnalysis(
|
|||||||
await resizeImageForVision(result.data, maxDimension);
|
await resizeImageForVision(result.data, maxDimension);
|
||||||
|
|
||||||
const base64 = resizedBuffer.toString("base64");
|
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) {
|
if (candidate.stickerName) {
|
||||||
setStickerInCache(candidate.stickerName, base64, resizedMime).catch(
|
uploadAndCacheSticker(
|
||||||
() => {},
|
candidate.stickerName,
|
||||||
);
|
resizedBuffer,
|
||||||
|
resizedMime,
|
||||||
|
).catch(() => {});
|
||||||
}
|
}
|
||||||
|
|
||||||
const part: MessageImagePart = {
|
const part: MessageImagePart = {
|
||||||
|
|||||||
Reference in New Issue
Block a user