Web-server refactor (#14)

* rename field

* Parse body support

* Changelog

* Parse query params

* Error handling for larger than content-length body
This commit is contained in:
Brahim Hadriche authored and GitHub committed 2022-11-26 17:25:40 -05:00
1 parent 3f5cb84696
commit 85209cb22e
9 files changed
+187 -75

No files matched your search

@@ -25,16 +25,15 @@ namespace Http
route = request.uri
if route.StartsWith("/api/command/play")
components = WebUtils.UrlQueryComponents(route)
if components["v"] = invalid
if request.query["v"] = invalid
response.Default(400, "Missing arg 'v'")
return true
end if
server.task.top.command = `play:${components["v"]}`
if components["redirect"] = "true"
server.task.top.command = `play:${request.query["v"]}`
if request.query["redirect"] = "true"
' 302 to prevent redirection to current host permanently
response.Redirect(`${InvidiousSettings.GetSelectedInstance()}/watch?v=${components["v"]}`, 302)
response.Redirect(`${InvidiousSettings.GetSelectedInstance()}/watch?v=${request.query["v"]}`, 302)
else
response.Default(204, "OK")
end if
@@ -15,11 +15,9 @@ namespace Http
return false
end if
components = WebUtils.UrlQueryComponents(route)
instances = []
if components.DoesExist("instances")
instances = components["instances"]
if request.query.DoesExist("instances")
instances = request.query["instances"]
if GetInterface(instances, "ifArray") = invalid
instances = [instances]
end if
@@ -46,11 +44,10 @@ namespace Http
return false
end if
components = WebUtils.UrlQueryComponents(route)
if components["token"] <> invalid and components["referer"] <> invalid
if request.query["token"] <> invalid and request.query["referer"] <> invalid
' Token is encoded twice for some reason
token = WebUtils.UrlUnescape(components["token"]).DecodeUriComponent()
referer = WebUtils.UrlUnescape(components["referer"])
token = WebUtils.UrlUnescape(request.query["token"]).DecodeUriComponent()
referer = WebUtils.UrlUnescape(request.query["referer"])
InvidiousSettings.SetAuthToken(token, referer)
server.task.top.login = true
end if
@@ -20,9 +20,8 @@ namespace Http
keys = ["app", "device", "invidious"]
components = WebUtils.UrlQueryComponents(route)
if components.DoesExist("key")
keys = components["key"]
if request.query.DoesExist("key")
keys = request.query["key"]
if GetInterface(keys, "ifArray") = invalid
keys = [keys]
end if