presence: game icon large image fallback (client behavior)

This commit is contained in:
Cynthia Foxwell 2025-05-01 21:55:23 -06:00
parent 9d0ce017a9
commit 4f5eae6dcb
Signed by: Cynosphere
SSH key fingerprint: SHA256:H3SM8ufP/uxqLwKSH7xY89TDnbR9uOHzjLoBr0tlajk

View file

@ -316,7 +316,35 @@ presence.callback = async function (msg, line) {
smallUrl = CDNEndpoints.APP_ASSET(activity.application_id, activity.assets.small_image); smallUrl = CDNEndpoints.APP_ASSET(activity.application_id, activity.assets.small_image);
} }
thumbnail = fixMediaProxyURL(smallUrl); const game = Games.find((game) => game.id == activity.application_id);
if (game?.icon) {
const gameIcon = `${CDNEndpoints.APP_ICON(game.id, game.icon)}?keep_aspect_ratio=false`;
image_links.push({label: "App Icon", url: gameIcon});
const largeImage = await fetch(gameIcon)
.then((res) => res.arrayBuffer())
.then((b) => Buffer.from(b));
const presenceImage = sharp(largeImage).resize(100, 100);
const smallImage = await fetch(smallUrl)
.then((res) => res.arrayBuffer())
.then((b) => Buffer.from(b));
const smallImageBuffer = await sharp(smallImage).resize(32, 32).toBuffer();
presenceImage.composite([
{
input: smallImageBuffer,
gravity: "southeast",
},
]);
files.push({
contents: await presenceImage.toBuffer(),
name: `${index}.png`,
});
thumbnail = `attachment://${index}.png`;
} else {
thumbnail = fixMediaProxyURL(smallUrl);
}
image_links.push({label: "Small Image", url: thumbnail}); image_links.push({label: "Small Image", url: thumbnail});
} }
} }