Add username to web app and state api (#50)

This commit is contained in:
Brahim Hadriche authored and GitHub committed 2023-02-21 13:54:13 -05:00
1 parent 5baab67bb4
commit 71453237c4
5 files changed
+26 -6

No files matched your search

+1
View File
@@ -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
@@ -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("/")
@@ -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
@@ -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()
+8 -1
View File
@@ -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 (<a href="${appState.invidious.logged_in_instance}" target="_blank">${appState.invidious.logged_in_instance}</a>)`
let loggedIn = 'Logged In '
if (appState.invidious.logged_in_username) {
loggedIn += `as "${appState.invidious.logged_in_username}"`
} else {
loggedIn += ": true"
}
loggedIn += ` (<a href="${appState.invidious.logged_in_instance}" target="_blank">${appState.invidious.logged_in_instance}</a>)`
document.getElementById("logged-in").innerHTML = loggedIn
} else {
document.getElementById("logged-in").innerHTML = "Logged In: false"
}