From 83238bd1d7c55a87ae2169f9e97411774c41b270 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Thu, 28 May 2026 22:23:28 +0200 Subject: cockpit: use the user icon if it is available and fix URL discovery --- cockpit/js/cockpit.js | 9 ++++++++- cockpit/js/config.js | 10 ++++++---- cockpit/js/student-common.js | 4 ++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/cockpit/js/cockpit.js b/cockpit/js/cockpit.js index f701706..30fc2a0 100644 --- a/cockpit/js/cockpit.js +++ b/cockpit/js/cockpit.js @@ -197,7 +197,14 @@ async function fetchAndUpdateStudentInfo() { } function updateStudentInfo() { - document.getElementById("student-info-icon").src = student.getIconUrl(); + // Try to replace the generic icon with the user's icon + var img = document.createElement('img'); + img.onload = function() { + document.getElementById("student-info-icon").src = img.src; + img = img.onload = null; + }; + student.getIconUrl().then( (url) => img.src = url ); + document.getElementById("student-info-name").innerHTML = `${student.name}`; if (student.graduation) { diff --git a/cockpit/js/config.js b/cockpit/js/config.js index 6ec5831..94dbfc2 100644 --- a/cockpit/js/config.js +++ b/cockpit/js/config.js @@ -22,14 +22,16 @@ function getCourseId() { return courseId; } -function getUserIconUrl(userId) { - return `https://lernplattform.bycs.de/pluginfile.php/${userId}/user/icon`; -} - function getCourseParticipantsUrl() { return `https://lernplattform.bycs.de/user/index.php?id=${courseId}`; } +async function getUserIconUrl(userId) { + const userRes = await fetch(`https://lernplattform.bycs.de/user/profile.php?id=${userId}`) + const userDoc = new DOMParser().parseFromString(await userRes.text(), 'text/html') + return userDoc.querySelector(".userpicture").src; +} + export { GRADUATION_DB, GRADUATION_DB_PARAMS_MAP, getCourseId, diff --git a/cockpit/js/student-common.js b/cockpit/js/student-common.js index 74cc845..3938380 100644 --- a/cockpit/js/student-common.js +++ b/cockpit/js/student-common.js @@ -9,8 +9,8 @@ class Student { this.group = group; } - getIconUrl() { - return getUserIconUrl(this.id); + async getIconUrl() { + return await getUserIconUrl(this.id); } } -- cgit v1.2.3