* rename field * Parse body support * Changelog * Parse query params * Error handling for larger than content-length body
59 lines
1.9 KiB
Plaintext
59 lines
1.9 KiB
Plaintext
import "pkg:/source/services/Invidious.bs"
|
|
import "pkg:/source/utils/General.bs"
|
|
|
|
namespace Http
|
|
|
|
class StateApiRouter extends HttpRouter
|
|
|
|
function new()
|
|
super()
|
|
|
|
m.Get("*", function(context as object) as boolean
|
|
request = context.request
|
|
response = context.response
|
|
|
|
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"]
|
|
|
|
if request.query.DoesExist("key")
|
|
keys = request.query["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: authToken <> invalid,
|
|
logged_in_instance: authToken <> invalid ? authToken.instance : invalid
|
|
}
|
|
end if
|
|
|
|
response.Json(state)
|
|
return true
|
|
end function)
|
|
end function
|
|
|
|
end class
|
|
|
|
end namespace
|