migrate to new badge api
we used to store badges on the discord cdn. since discord is now making it harder to use their cdn for such purposes (due to expiring links), we are forced to stop using it thus, badges are now stored on our server, accessible via https://badges.vencord.dev. The full list of badges is now at https://badges.vencord.dev/badges.json
This commit is contained in:
parent
8e1546be00
commit
fccdd3dc08
|
@ -22,14 +22,13 @@ import ErrorBoundary from "@components/ErrorBoundary";
|
||||||
import { Flex } from "@components/Flex";
|
import { Flex } from "@components/Flex";
|
||||||
import { Heart } from "@components/Heart";
|
import { Heart } from "@components/Heart";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import { Logger } from "@utils/Logger";
|
|
||||||
import { Margins } from "@utils/margins";
|
import { Margins } from "@utils/margins";
|
||||||
import { isPluginDev } from "@utils/misc";
|
import { isPluginDev } from "@utils/misc";
|
||||||
import { closeModal, Modals, openModal } from "@utils/modal";
|
import { closeModal, Modals, openModal } from "@utils/modal";
|
||||||
import definePlugin from "@utils/types";
|
import definePlugin from "@utils/types";
|
||||||
import { Forms, Toasts } from "@webpack/common";
|
import { Forms, Toasts } from "@webpack/common";
|
||||||
|
|
||||||
const CONTRIBUTOR_BADGE = "https://cdn.discordapp.com/attachments/1033680203433660458/1092089947126780035/favicon.png";
|
const CONTRIBUTOR_BADGE = "https://vencord.dev/assets/favicon.png";
|
||||||
|
|
||||||
const ContributorBadge: ProfileBadge = {
|
const ContributorBadge: ProfileBadge = {
|
||||||
description: "Vencord Contributor",
|
description: "Vencord Contributor",
|
||||||
|
@ -45,7 +44,7 @@ const ContributorBadge: ProfileBadge = {
|
||||||
link: "https://github.com/Vendicated/Vencord"
|
link: "https://github.com/Vendicated/Vencord"
|
||||||
};
|
};
|
||||||
|
|
||||||
let DonorBadges = {} as Record<string, Pick<ProfileBadge, "image" | "description">[]>;
|
let DonorBadges = {} as Record<string, Array<Record<"tooltip" | "badge", string>>>;
|
||||||
|
|
||||||
async function loadBadges(noCache = false) {
|
async function loadBadges(noCache = false) {
|
||||||
DonorBadges = {};
|
DonorBadges = {};
|
||||||
|
@ -54,19 +53,8 @@ async function loadBadges(noCache = false) {
|
||||||
if (noCache)
|
if (noCache)
|
||||||
init.cache = "no-cache";
|
init.cache = "no-cache";
|
||||||
|
|
||||||
const badges = await fetch("https://gist.githubusercontent.com/Vendicated/51a3dd775f6920429ec6e9b735ca7f01/raw/badges.csv", init)
|
DonorBadges = await fetch("https://badges.vencord.dev/badges.json", init)
|
||||||
.then(r => r.text());
|
.then(r => r.json());
|
||||||
|
|
||||||
const lines = badges.trim().split("\n");
|
|
||||||
if (lines.shift() !== "id,tooltip,image") {
|
|
||||||
new Logger("BadgeAPI").error("Invalid badges.csv file!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const line of lines) {
|
|
||||||
const [id, description, image] = line.split(",");
|
|
||||||
(DonorBadges[id] ??= []).push({ image, description });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default definePlugin({
|
export default definePlugin({
|
||||||
|
@ -127,7 +115,8 @@ export default definePlugin({
|
||||||
|
|
||||||
getDonorBadges(userId: string) {
|
getDonorBadges(userId: string) {
|
||||||
return DonorBadges[userId]?.map(badge => ({
|
return DonorBadges[userId]?.map(badge => ({
|
||||||
...badge,
|
image: badge.badge,
|
||||||
|
description: badge.tooltip,
|
||||||
position: BadgePosition.START,
|
position: BadgePosition.START,
|
||||||
props: {
|
props: {
|
||||||
style: {
|
style: {
|
||||||
|
|
Loading…
Reference in a new issue