Ground work for invidious instance selection (#11)
* Ground work for invidious instance selection * Display logged in instance * Show instances * Reorder instances * Instance management * Add todos * Changelog * Add instances link, trim trailing slash * Small tweaks
This commit is contained in:
1 parent
1d9dc3ecda
commit
a248318c54
14 files changed
+411
-130
No files matched your search
@@ -34,7 +34,7 @@ namespace Http
|
||||
server.task.top.command = `play:${components["v"]}`
|
||||
if components["redirect"] = "true"
|
||||
' 302 to prevent redirection to current host permanently
|
||||
response.Redirect(`${Invidious.GetCurrentHost()}/watch?v=${components["v"]}`, 302)
|
||||
response.Redirect(`${InvidiousSettings.GetSelectedInstance()}/watch?v=${components["v"]}`, 302)
|
||||
else
|
||||
response.Default(204, "OK")
|
||||
end if
|
||||
|
||||
@@ -5,25 +5,57 @@ namespace Http
|
||||
function new()
|
||||
super()
|
||||
|
||||
' TODO: use POST once supported
|
||||
m.Get("*", function(context as object) as boolean
|
||||
request = context.request
|
||||
response = context.response
|
||||
|
||||
route = request.uri
|
||||
if not route.StartsWith("/invidious/set-instances")
|
||||
return false
|
||||
end if
|
||||
|
||||
components = WebUtils.UrlQueryComponents(route)
|
||||
|
||||
instances = []
|
||||
if components.DoesExist("instances")
|
||||
instances = components["instances"]
|
||||
if GetInterface(instances, "ifArray") = invalid
|
||||
instances = [instances]
|
||||
end if
|
||||
end if
|
||||
|
||||
for i = 0 to instances.Count() - 1
|
||||
if instances[i].right(1) = "/"
|
||||
instances[i] = instances[i].left(instances[i].len() - 1)
|
||||
end if
|
||||
end for
|
||||
|
||||
InvidiousSettings.SetRegistryInstances(instances)
|
||||
response.Default(200, "OK")
|
||||
return true
|
||||
end function)
|
||||
|
||||
m.Get("*", function(context as object) as boolean
|
||||
request = context.request
|
||||
response = context.response
|
||||
server = context.server
|
||||
|
||||
uri = request.uri
|
||||
if uri.StartsWith(Invidious.TOKEN_CALLBACK)
|
||||
components = WebUtils.UrlQueryComponents(uri)
|
||||
if components["token"] <> invalid
|
||||
' Token is encoded twice for some reason
|
||||
token = WebUtils.UrlUnescape(components["token"]).DecodeUriComponent()
|
||||
print(`Got Token: ${token}`)
|
||||
RegistryUtils.Write("invidious_token", token)
|
||||
server.task.top.login = true
|
||||
end if
|
||||
response.Redirect("/", 302)
|
||||
return true
|
||||
route = request.uri
|
||||
if not route.StartsWith(Invidious.TOKEN_CALLBACK)
|
||||
return false
|
||||
end if
|
||||
return false
|
||||
|
||||
components = WebUtils.UrlQueryComponents(route)
|
||||
if components["token"] <> invalid and components["referer"] <> invalid
|
||||
' Token is encoded twice for some reason
|
||||
token = WebUtils.UrlUnescape(components["token"]).DecodeUriComponent()
|
||||
referer = WebUtils.UrlUnescape(components["referer"])
|
||||
InvidiousSettings.SetAuthToken(token, referer)
|
||||
server.task.top.login = true
|
||||
end if
|
||||
response.Redirect("/", 302)
|
||||
return true
|
||||
end function)
|
||||
end function
|
||||
|
||||
|
||||
@@ -8,18 +8,47 @@ namespace Http
|
||||
function new()
|
||||
super()
|
||||
|
||||
m.Get("/api/state", function(context as object) as boolean
|
||||
m.Get("*", function(context as object) as boolean
|
||||
request = context.request
|
||||
response = context.response
|
||||
|
||||
state = {
|
||||
app: GetAppInfo(),
|
||||
device: GetDeviceInfo(),
|
||||
invidious: {
|
||||
host: Invidious.GetCurrentHost(),
|
||||
route = request.uri
|
||||
' TODO: this is not the right filtering. /api/state/something will go through, which is not correct
|
||||
if not route.StartsWith("/api/state")
|
||||
return false
|
||||
end if
|
||||
|
||||
keys = ["app", "device", "invidious"]
|
||||
|
||||
components = WebUtils.UrlQueryComponents(route)
|
||||
if components.DoesExist("key")
|
||||
keys = components["key"]
|
||||
if GetInterface(keys, "ifArray") = invalid
|
||||
keys = [keys]
|
||||
end if
|
||||
end if
|
||||
|
||||
state = {}
|
||||
|
||||
if ArrayIndexOf(keys, "app") <> -1
|
||||
state["app"] = GetAppInfo()
|
||||
end if
|
||||
|
||||
if ArrayIndexOf(keys, "device") <> -1
|
||||
state["device"] = GetDeviceInfo()
|
||||
end if
|
||||
|
||||
if ArrayIndexOf(keys, "invidious") <> -1
|
||||
authToken = InvidiousSettings.GetAuthToken()
|
||||
state["invidious"] = {
|
||||
instances: InvidiousSettings.GetCurrentInstances(),
|
||||
selected_instance: InvidiousSettings.GetSelectedInstance(),
|
||||
auth_url: Invidious.GetAuthorizeTokenLink(),
|
||||
logged_in: Invidious.GetAuthenticationHeaders() <> invalid
|
||||
logged_in: authToken <> invalid,
|
||||
logged_in_instance: authToken <> invalid ? authToken.instance : invalid
|
||||
}
|
||||
}
|
||||
end if
|
||||
|
||||
response.Json(state)
|
||||
return true
|
||||
end function)
|
||||
|
||||
Reference in new issue
Block a user