Command api refactor
This commit is contained in:
1 parent
0409e61b5f
commit
953403f952
2 files changed
+31
-31
No files matched your search
@@ -5,35 +5,31 @@ namespace Http
|
|||||||
function new()
|
function new()
|
||||||
super()
|
super()
|
||||||
|
|
||||||
m.Get("/api/command/logout", function(context as object) as boolean
|
m.Post("/api/command", function(context as object) as boolean
|
||||||
response = context.response
|
|
||||||
server = context.server
|
|
||||||
|
|
||||||
if Invidious.Logout()
|
|
||||||
server.task.top.login = false
|
|
||||||
end if
|
|
||||||
|
|
||||||
response.Default(204, "OK")
|
|
||||||
return true
|
|
||||||
end function)
|
|
||||||
|
|
||||||
m.Get("/api/command/play", function(context as object) as boolean
|
|
||||||
request = context.request
|
request = context.request
|
||||||
response = context.response
|
response = context.response
|
||||||
server = context.server
|
server = context.server
|
||||||
|
|
||||||
if request.query["v"] = invalid
|
payload = request.Json()
|
||||||
response.Default(400, "Missing arg 'v'")
|
if payload = invalid
|
||||||
|
response.Default(400, "Invalid payload")
|
||||||
return true
|
return true
|
||||||
end if
|
end if
|
||||||
|
|
||||||
server.task.top.command = `play:${request.query["v"]}`
|
if payload.command = "logout"
|
||||||
if request.query["redirect"] = "true"
|
if Invidious.Logout()
|
||||||
' 302 to prevent redirection to current host permanently
|
server.task.top.login = false
|
||||||
response.Redirect(`${InvidiousSettings.GetSelectedInstance()}/watch?v=${request.query["v"]}`, 302)
|
|
||||||
else
|
|
||||||
response.Default(204, "OK")
|
|
||||||
end if
|
end if
|
||||||
|
response.Default(204, "OK")
|
||||||
|
return true
|
||||||
|
else if payload.command = "play"
|
||||||
|
videoId = payload.videoId
|
||||||
|
server.task.top.command = `play:${videoId}`
|
||||||
|
response.Default(204, "OK")
|
||||||
|
return true
|
||||||
|
end if
|
||||||
|
|
||||||
|
response.Default(400, `Invalid command: ${payload.command}`)
|
||||||
return true
|
return true
|
||||||
end function)
|
end function)
|
||||||
end function
|
end function
|
||||||
|
|||||||
+14
-10
@@ -82,7 +82,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Logout() {
|
function Logout() {
|
||||||
fetch('/api/command/logout')
|
PostJson('/api/command', { command: "logout" })
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
})
|
})
|
||||||
@@ -100,7 +100,7 @@
|
|||||||
alert("Please set video id")
|
alert("Please set video id")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fetch(`/api/command/play?v=${v}`)
|
PostJson('/api/command', { command: "play", videoId: v })
|
||||||
.catch(function (err) {
|
.catch(function (err) {
|
||||||
alert(err)
|
alert(err)
|
||||||
});
|
});
|
||||||
@@ -210,14 +210,7 @@ ${JSON.stringify(window.appState.device, null, 2)}
|
|||||||
.filter(a => !!a)
|
.filter(a => !!a)
|
||||||
.map(a => a.innerText);
|
.map(a => a.innerText);
|
||||||
|
|
||||||
fetch('/invidious/instances',
|
PostJson('/invidious/instances', instances)
|
||||||
{
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
method: "POST",
|
|
||||||
body: JSON.stringify(instances)
|
|
||||||
})
|
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
alert("Instances updated. Restart Playlet to reflect changes.")
|
alert("Instances updated. Restart Playlet to reflect changes.")
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
@@ -227,6 +220,17 @@ ${JSON.stringify(window.appState.device, null, 2)}
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function PostJson(url, payload) {
|
||||||
|
return fetch(url,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify(payload)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function Initialize() {
|
function Initialize() {
|
||||||
fetch("/api/state")
|
fetch("/api/state")
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
|
|||||||
Reference in new issue
Block a user