GlobalBadges: Allow Different API URLs
This commit is contained in:
parent
f062ae3d57
commit
8cfe2ab7f6
2 changed files with 11 additions and 2 deletions
|
|
@ -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;
|
||||
})
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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 });
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue