GlobalBadges: Allow Different API URLs

This commit is contained in:
thororen1234 2025-11-17 12:26:19 -05:00
parent f062ae3d57
commit 8cfe2ab7f6
No known key found for this signature in database
2 changed files with 11 additions and 2 deletions

View file

@ -73,5 +73,15 @@ export const settings = definePluginSettings({
description: "Show Replugged Badges",
default: true,
restartNeeded: false
},
apiUrl: {
type: OptionType.STRING,
description: "API to use",
default: "https://badges.equicord.org/",
restartNeeded: false,
onChange: (e => {
if (!e || !e.startsWith("https://")) return settings.store.apiUrl = "https://badges.equicord.org/";
return e;
})
}
});

View file

@ -9,7 +9,6 @@ import { classNameFactory } from "@api/Styles";
import { settings } from "./settings";
import { BadgeCache } from "./types";
const API_URL = "https://badges.equicord.org/";
const cache = new Map<string, BadgeCache>();
const EXPIRES = 1000 * 60 * 15;
@ -45,7 +44,7 @@ export const fetchBadges = (id: string): BadgeCache["badges"] | undefined => {
return {};
}
fetch(`${API_URL}${id}?seperated=true&services=${services.join(",")}`)
fetch(`${settings.store.apiUrl}${id}?seperated=true&services=${services.join(",")}`)
.then(res => res.json() as Promise<{ status: number; badges: BadgeCache["badges"]; }>)
.then(body => {
cache.set(id, { badges: body.badges, expires: Date.now() + EXPIRES });