56 lines
2.0 KiB
Plaintext
56 lines
2.0 KiB
Plaintext
namespace Http
|
|
|
|
class InvidiousRouter extends HttpRouter
|
|
|
|
function new()
|
|
super()
|
|
|
|
m.Post("/invidious/instances", function(context as object) as boolean
|
|
request = context.request
|
|
response = context.response
|
|
|
|
instances = request.Json()
|
|
|
|
if GetInterface(instances, "ifArray") = invalid
|
|
response.Default(400, "Expected json array")
|
|
return true
|
|
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(Invidious.TOKEN_CALLBACK, function(context as object) as boolean
|
|
request = context.request
|
|
response = context.response
|
|
server = context.server
|
|
|
|
if request.query["token"] <> invalid and request.query["ref"] <> invalid
|
|
' Token is encoded twice for some reason
|
|
token = request.query["token"].DecodeUri().DecodeUriComponent()
|
|
referer = request.query["ref"].DecodeUri()
|
|
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("/")
|
|
return true
|
|
end function)
|
|
end function
|
|
|
|
end class
|
|
|
|
end namespace
|