2024-10-03 00:32:38 +01:00
|
|
|
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) {
|
2024-10-08 01:19:45 +01:00
|
|
|
if (badge.ForUrl.includes(",")) {
|
|
|
|
const urls = badge.ForUrl.replaceAll(" ", "").split(",");
|
|
|
|
for (const url of urls) {
|
|
|
|
this.processUri(url, badge, goalBadges, urlBadges);
|
|
|
|
}
|
2024-10-03 00:32:38 +01:00
|
|
|
} else {
|
2024-10-08 01:19:45 +01:00
|
|
|
this.processUri(badge.ForUrl, badge, goalBadges, urlBadges);
|
2024-10-03 00:32:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BadgeCache.UrlBadges = urlBadges;
|
|
|
|
BadgeCache.GoalBadges = goalBadges;
|
|
|
|
}
|
2024-10-08 01:19:45 +01:00
|
|
|
|
|
|
|
private static processUri(uri:string, badge: Badge, goalBadges: FunkyArray<string, Badge>, urlBadges: FunkyArray<string, Badge>) {
|
|
|
|
const urlParts = uri.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);
|
|
|
|
}
|
|
|
|
}
|
2024-10-03 00:32:38 +01:00
|
|
|
}
|