t00-multiuser/server/objects/BadgeCache.ts

30 lines
923 B
TypeScript
Raw Normal View History

import Badge from "../entities/Badge";
import FunkyArray from "funky-array";
import BadgeService from "../services/BadgeService";
export default abstract class BadgeCache {
public static UrlBadges:FunkyArray<string, Badge>;
public static GoalBadges:FunkyArray<string, Badge>;
public static async RefreshCache() {
const badges = await BadgeService.LoadAll();
const urlBadges = new FunkyArray<string, Badge>();
const goalBadges = new FunkyArray<string, Badge>();
for (const badge of badges) {
const urlParts = badge.ForUrl.split("://");
let url = urlParts[1].replace("www.", "").toLowerCase().replace(".htm", "").replace(".html", "");
if (url.endsWith("/index")) {
url = url.replace("/index", "/");
}
if (urlParts[0] === "mp") {
goalBadges.set(url, badge);
} else {
urlBadges.set(url, badge);
}
}
BadgeCache.UrlBadges = urlBadges;
BadgeCache.GoalBadges = goalBadges;
}
}