diff --git a/frontend/src/api/main.ts b/frontend/src/api/main.ts index 45af4d4..503c31e 100644 --- a/frontend/src/api/main.ts +++ b/frontend/src/api/main.ts @@ -60,4 +60,28 @@ export const SubjectNames: { [key: string]: string } = { }; export function JSESSIONIDCookieString(JSESSIONID: string): string { return `JSESSIONID=${JSESSIONID}; max-age=600; secure; samesite=none; domain=.theschedule.de`; +} +export async function getCommitHash(): Promise { + const result = await fetch("https://api.github.com/repos/ixhbinphoenix/bne/commits/master", { + method: "GET" + }) as unknown as Array + try { + return JSON.parse(await readStream(result.body)).sha.substring(0, 7) + } + catch (error) { + return Promise.reject(error) + } +} +async function readStream(stream: ReadableStream) { + const textDecode = new TextDecoder(); + const chunks = []; + const reader = stream.getReader(); + while (true) { + const { done, value } = await reader.read(); + if (done) { + break; + } + chunks.push(textDecode.decode(value)); + } + return chunks.join(""); } \ No newline at end of file diff --git a/frontend/src/components/plan-components/Settings.tsx b/frontend/src/components/plan-components/Settings.tsx index e54c618..6838ae1 100644 --- a/frontend/src/components/plan-components/Settings.tsx +++ b/frontend/src/components/plan-components/Settings.tsx @@ -12,8 +12,10 @@ import Logout from "./settings-components/Logout"; import UserData from "./settings-components/UserData"; import { onSwipe } from "../../api/Touch"; import { accountIsVerified, resendVerifyEmail } from "../../api/theBackend"; +import { getCommitHash } from "../../api/main"; export default function Settings(): JSX.Element { + const [commitHash, setCommitHash] = useState(""); const [resendMessage, setResendMessage] = useState("Link erneut versenden"); const [NotVerifiedMessage, setNotVerifiedMessage] = useState({ display: "none" }); const [TopbarColor, setTopbarColor] = useState({ "background-color": "var(--highlight-blue)" }); @@ -72,6 +74,11 @@ export default function Settings(): JSX.Element { const [pageContent, setPageContent] = useState(Menu); const [username, setUsername] = useState(""); useEffect(() => { + getCommitHash().then( + (result) => { + setCommitHash(result) + } + ) showNotVerifiedMessage(); const usernameRaw = localStorage.getItem("untis_username"); const nameParts = usernameRaw?.split("_"); @@ -88,10 +95,11 @@ export default function Settings(): JSX.Element { }, [pageContent]); return ( -
+
{username}
{notVerifiedMessageDiv} +

Version: {commitHash}