utility.presence: remap media proxy urls

This commit is contained in:
Cynthia Foxwell 2024-07-07 13:15:43 -06:00
parent 95b24f8e7f
commit 8c95848a70

View file

@ -1907,7 +1907,30 @@ presence.callback = async function (msg, line) {
largeUrl = `https://cdn.discordapp.com/app-assets/${activity.application_id}/${activity.assets.large_image}.png`; largeUrl = `https://cdn.discordapp.com/app-assets/${activity.application_id}/${activity.assets.large_image}.png`;
} }
image_links.push(`[Large Image](${largeUrl})`); let fixedLargeUrl = largeUrl;
if (fixedLargeUrl.includes("media.discordapp.net")) {
if (fixedLargeUrl.includes("/external/")) {
const split = fixedLargeUrl
.replace("https://media.discordapp.net/external/", "")
.split("/");
split.shift();
let query = "";
if (split[0].startsWith("%")) {
query = decodeURIComponent(split.shift());
}
split[0] = split[0] + ":/";
fixedLargeUrl = split.join("/") + query;
} else {
fixedLargeUrl = fixedLargeUrl.replace(
"media.discordapp.net",
"cdn.discordapp.com"
);
}
}
image_links.push(`[Large Image](${fixedLargeUrl})`);
let smallUrl; let smallUrl;
if (activity.assets.small_image != null) { if (activity.assets.small_image != null) {
@ -1925,7 +1948,30 @@ presence.callback = async function (msg, line) {
smallUrl = `https://cdn.discordapp.com/app-assets/${activity.application_id}/${activity.assets.small_image}.png`; smallUrl = `https://cdn.discordapp.com/app-assets/${activity.application_id}/${activity.assets.small_image}.png`;
} }
image_links.push(`[Small Image](${smallUrl})`); let fixedSmallUrl = smallUrl;
if (fixedSmallUrl.includes("media.discordapp.net")) {
if (fixedSmallUrl.includes("/external/")) {
const split = fixedSmallUrl
.replace("https://media.discordapp.net/external/", "")
.split("/");
split.shift();
let query = "";
if (split[0].startsWith("%")) {
query = decodeURIComponent(split.shift());
}
split[0] = split[0] + ":/";
fixedSmallUrl = split.join("/") + query;
} else {
fixedSmallUrl = fixedSmallUrl.replace(
"media.discordapp.net",
"cdn.discordapp.com"
);
}
}
image_links.push(`[Small Image](${fixedSmallUrl})`);
} }
const largeImage = await fetch(largeUrl) const largeImage = await fetch(largeUrl)
@ -1987,6 +2033,30 @@ presence.callback = async function (msg, line) {
embed.thumbnail = { embed.thumbnail = {
url: `attachment://${index}.png`, url: `attachment://${index}.png`,
}; };
let fixedSmallUrl = smallUrl;
if (fixedSmallUrl.includes("media.discordapp.net")) {
if (fixedSmallUrl.includes("/external/")) {
const split = fixedSmallUrl
.replace("https://media.discordapp.net/external/", "")
.split("/");
split.shift();
let query = "";
if (split[0].startsWith("%")) {
query = decodeURIComponent(split.shift());
}
split[0] = split[0] + ":/";
fixedSmallUrl = split.join("/") + query;
} else {
fixedSmallUrl = fixedSmallUrl.replace(
"media.discordapp.net",
"cdn.discordapp.com"
);
}
}
embed.fields.push({ embed.fields.push({
name: "\u200b", name: "\u200b",
value: `[Small Image](${smallUrl})`, value: `[Small Image](${smallUrl})`,