Play API prototype (#8)
* Play API prototype * Web app * Drag and drop support * Handle different urls * Fix redirect * Increase max connections * changelog * Limit timeout * Use fetch * Redirects * Formatting
This commit is contained in:
1 parent
192eec9519
commit
651bb54dee
15 files changed
+180
-39
No files matched your search
@@ -0,0 +1,38 @@
|
||||
namespace Http
|
||||
|
||||
class CommandsApiRouter extends HttpRouter
|
||||
|
||||
function new()
|
||||
super()
|
||||
|
||||
m.Get("*", function(context as object) as boolean
|
||||
request = context.request
|
||||
response = context.response
|
||||
server = context.server
|
||||
|
||||
route = request.uri
|
||||
|
||||
if route.StartsWith("/api/command/play")
|
||||
components = WebUtils.UrlQueryComponents(route)
|
||||
if components["v"] = invalid
|
||||
response.Default(400, "Missing arg 'v'")
|
||||
return true
|
||||
end if
|
||||
|
||||
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)
|
||||
else
|
||||
response.Default(200, "OK")
|
||||
end if
|
||||
return true
|
||||
end if
|
||||
|
||||
return false
|
||||
end function)
|
||||
end function
|
||||
|
||||
end class
|
||||
|
||||
end namespace
|
||||
@@ -10,12 +10,12 @@ namespace Http
|
||||
response = context.response
|
||||
|
||||
method = request.method
|
||||
route = request.uri
|
||||
uri = request.uri
|
||||
|
||||
if method = ""
|
||||
response.Default(400, "You sent a request that the server couldn't understand.")
|
||||
else
|
||||
response.Default(404, `Cannot ${method} ${route}`)
|
||||
response.Default(404, `Cannot ${method} ${uri}`)
|
||||
end if
|
||||
|
||||
return true
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace Http
|
||||
RegistryUtils.Write("invidious_token", token)
|
||||
server.task.top.login = true
|
||||
end if
|
||||
response.Redirect("/index.html?tab=settings")
|
||||
response.Redirect("/", 302)
|
||||
return true
|
||||
end if
|
||||
return false
|
||||
|
||||
Reference in new issue
Block a user