From 482c006782c8270801d82e82e113fa5fba6b774d Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Mon, 28 Sep 2026 15:56:31 +0200 Subject: utils: move get*Id functions into utils-common.ts --- src/utils-common.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/utils-common.ts') diff --git a/src/utils-common.ts b/src/utils-common.ts index 153bbaa..7bca889 100644 --- a/src/utils-common.ts +++ b/src/utils-common.ts @@ -22,6 +22,20 @@ export function datetimeStringNow() { return DATETIME_FMT.format(new Date()); } +declare global { + var M: { cfg: { userId: number; courseId: number } }; +} + +export function getUserId(): number { + // M is exported by Moodle + return globalThis.M.cfg.userId; +} + +export function getCourseId(): number { + // M is exported by Moodle + return globalThis.M.cfg.courseId; +} + // TODO(muhq): Cache the retrieved URL export async function getUserIconUrl(userId: number): Promise { const userRes = await fetch(`https://lernplattform.bycs.de/user/profile.php?id=${userId}`); -- cgit v1.2.3