aboutsummaryrefslogtreecommitdiff
path: root/src/utils-common.ts
blob: f3ad944339e0ca3c91f0a69e6d44eb16b3a0aaf1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
"use strict";

export const DATE_FMT = new Intl.DateTimeFormat("de-DE", { month: "numeric", day: "numeric", year: "numeric"});

export const DATETIME_FMT = new Intl.DateTimeFormat("de-DE", { month: "numeric", day: "numeric", year: "numeric", hour: "numeric", minute: "numeric" });

export function dateStringNow() {
	return DATE_FMT.format(new Date());
}

export function datetimeStringNow() {
	return DATETIME_FMT.format(new Date());
}

// TODO(muhq): Cache the retrieved URL
export async function getUserIconUrl(userId: number): Promise<string> {
	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");
	if (userpicture === null) {
		return "";
	}

	return (userpicture as HTMLImageElement).src ?? "";
}