Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add username to web app and state api #50

Merged
merged 1 commit into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("/")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 8 additions & 3 deletions playlet-lib/src/source/services/InvidiousSettings.bs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 8 additions & 1 deletion playlet-web/public/index.v1.html
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,14 @@ <h5>Feedback is welcome over at: <a id="feedback-url" href="https://github.com/i
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"
}
Expand Down