diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b16135f..734b5762 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added - SponsorBlock notification +- Invidious username to web app v1 ### Fixed - Crash in case GetLocalIpAddress() returns invalid diff --git a/playlet-lib/src/components/WebServer/Middleware/InvidiousRouter.bs b/playlet-lib/src/components/WebServer/Middleware/InvidiousRouter.bs index 22b3d048..91be45ff 100644 --- a/playlet-lib/src/components/WebServer/Middleware/InvidiousRouter.bs +++ b/playlet-lib/src/components/WebServer/Middleware/InvidiousRouter.bs @@ -36,7 +36,13 @@ namespace Http ' Token is encoded twice for some reason token = request.query["token"].DecodeUri().DecodeUriComponent() referer = request.query["ref"].DecodeUri() - InvidiousSettings.SetAuthToken(token, referer) + username = request.query["username"] + ' TODO: remove null check after 6 months of https://github.com/iv-org/invidious/pull/3603 + if username <> invalid + username = username.DecodeUriComponent() + end if + + InvidiousSettings.SetAuthToken(token, referer, username) server.task.top.login = true end if response.Redirect("/") diff --git a/playlet-lib/src/components/WebServer/Middleware/StateApiRouter.bs b/playlet-lib/src/components/WebServer/Middleware/StateApiRouter.bs index 991cec7b..e13a34d6 100644 --- a/playlet-lib/src/components/WebServer/Middleware/StateApiRouter.bs +++ b/playlet-lib/src/components/WebServer/Middleware/StateApiRouter.bs @@ -38,7 +38,8 @@ namespace Http selected_instance: InvidiousSettings.GetSelectedInstance(), auth_url: Invidious.GetAuthorizeTokenLink(), logged_in: authToken <> invalid, - logged_in_instance: authToken <> invalid ? authToken.instance : invalid + logged_in_instance: authToken <> invalid ? authToken.instance : invalid, + logged_in_username: authToken <> invalid ? authToken.username : invalid } end if diff --git a/playlet-lib/src/source/services/InvidiousSettings.bs b/playlet-lib/src/source/services/InvidiousSettings.bs index cf7a3ebe..74c671bd 100644 --- a/playlet-lib/src/source/services/InvidiousSettings.bs +++ b/playlet-lib/src/source/services/InvidiousSettings.bs @@ -36,11 +36,16 @@ namespace InvidiousSettings return instances[0] end function - function SetAuthToken(token as string, instance as string) - json = FormatJson({ + function SetAuthToken(token as string, instance as string, username as dynamic) + obj = { token: token, instance: instance - }) + } + if username <> invalid + obj.username = username + end if + + json = FormatJson(obj) RegistryUtils.Write(RegistryUtils.INVIDIOUS_TOKEN, json) instances = InvidiousSettings.GetCurrentInstances() diff --git a/playlet-web/public/index.v1.html b/playlet-web/public/index.v1.html index dfa1fa08..d04cd220 100644 --- a/playlet-web/public/index.v1.html +++ b/playlet-web/public/index.v1.html @@ -261,7 +261,14 @@ ${JSON.stringify(window.appState.invidious, null, 2)} document.getElementById("app-version").innerText = `Version: ${appState.app.version}` if (appState.invidious.logged_in) { - document.getElementById("logged-in").innerHTML = `Logged In: true (${appState.invidious.logged_in_instance})` + let loggedIn = 'Logged In ' + if (appState.invidious.logged_in_username) { + loggedIn += `as "${appState.invidious.logged_in_username}"` + } else { + loggedIn += ": true" + } + loggedIn += ` (${appState.invidious.logged_in_instance})` + document.getElementById("logged-in").innerHTML = loggedIn } else { document.getElementById("logged-in").innerHTML = "Logged In: false" }