aboutsummaryrefslogtreecommitdiff
path: root/src/utils-common.ts
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2026-09-29 18:13:59 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2026-09-29 18:13:59 +0200
commit735d943097c64764c2b891368b7dd61b716e3e81 (patch)
tree5d311dbad81c9b48cb7440464e0f658ae78a456d /src/utils-common.ts
parent03ba4caf8f59c90bc637f8ab0fc7ce232c6f4926 (diff)
downloadbycs-sol-735d943097c64764c2b891368b7dd61b716e3e81.tar.gz
bycs-sol-735d943097c64764c2b891368b7dd61b716e3e81.zip
utils: cache user icon urls
Diffstat (limited to 'src/utils-common.ts')
-rw-r--r--src/utils-common.ts19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/utils-common.ts b/src/utils-common.ts
index 7bca889..d644b10 100644
--- a/src/utils-common.ts
+++ b/src/utils-common.ts
@@ -36,8 +36,20 @@ export function getCourseId(): number {
return globalThis.M.cfg.courseId;
}
-// TODO(muhq): Cache the retrieved URL
+export class CourseLocalStorage {
+ static getItem(key: string) {
+ return localStorage.getItem(`${key}-${getCourseId()}`);
+ }
+
+ static setItem(key: string, val: string) {
+ return localStorage.setItem(`${key}-${getCourseId()}`, val);
+ }
+}
+
export async function getUserIconUrl(userId: number): Promise<string> {
+ let url = CourseLocalStorage.getItem(`bycs-sol-user-icon-${userId}`);
+ if (url) return url;
+
const userRes = await fetch(`https://lernplattform.bycs.de/user/profile.php?id=${userId}`);
const userDoc = new DOMParser().parseFromString(await userRes.text(), "text/html");
const userpicture = userDoc.querySelector(".userpicture");
@@ -45,7 +57,10 @@ export async function getUserIconUrl(userId: number): Promise<string> {
return "";
}
- return (userpicture as HTMLImageElement).src ?? "";
+ url = (userpicture as HTMLImageElement).src ?? "";
+ CourseLocalStorage.setItem(`bycs-sol-user-icon-${userId}`, url);
+
+ return url;
}
// SplitMix32 implementation taken from: