* Dial+Lounge API PoC * format * Fix for chrome * comments * Rate limit and logger stuff * rename route * remove invalid routes * remove device image * Simplify device description * command test * Lint fix * register pairing code * tv code UI * Lint fix * Avoid creating lots of objects * dpad command * small refactor * tweak * validation * timer * fix * Revert "timer" This reverts commit e349565910882408898c9bddda55dadaa9d743de. * Commands * setVolume command * lounge service timer * Some state messages * Lint fix * player state sync * voice handler * Adjustments, and add a TODO list * Lint fix * comment * play at timestamp * Remote screen UI * UI adjustment * Small refactor * Refactor long polling * Add TODO * Manage logging a bit better to avoid spam in DIAL server * cache dial file * logging * comment * Join lounge lazily * long poller tweak * ui tweak * set shouldQuit field * remote connect notification * Lint fix * Randomize device id, new device on start * Lint fix * Lounge disconnect on start * Speed up lounge by not blocking on sent messages * add version to lounge data saved * dial server fix rendezvous * todo * no message * Display network name * playlist changes * Lint fix * tweak params * tweak * player state * comments * Refactor Video Queue (#295) * Refactor Video Queue * Video queue and playlists * Web app casting * queue playlist notification * VideoQueueView work * restore properties * changes * queue notification and previous/next state * Lint fix * very basic error handling * Update changelog and privacy policy --------- Co-authored-by: github-action linter <githubaction@githubaction.com>
115 lines
3.6 KiB
Plaintext
115 lines
3.6 KiB
Plaintext
import "pkg:/components/Services/Invidious/InvidiousToContentNode.bs"
|
|
import "pkg:/components/VideoQueue/VideoQueueUtils.bs"
|
|
import "pkg:/source/utils/MathUtils.bs"
|
|
|
|
namespace Http
|
|
|
|
class VideoQueueRouter extends HttpRouter
|
|
|
|
function new(server as object)
|
|
super()
|
|
|
|
task = server.task
|
|
m.videoQueueNode = task.videoQueue
|
|
m.invidiousNode = task.invidious
|
|
m.invidiousService = new Invidious.InvidiousService(m.invidiousNode)
|
|
end function
|
|
|
|
@get("/api/queue")
|
|
function GetQueue(context as object) as boolean
|
|
response = context.response
|
|
|
|
queue = VideoQueueUtils.GetQueueDto(m.videoQueueNode)
|
|
response.Json(queue)
|
|
return true
|
|
end function
|
|
|
|
@post("/api/queue")
|
|
function AddToQueue(context as object) as boolean
|
|
request = context.request
|
|
response = context.response
|
|
|
|
payload = request.Json()
|
|
if payload = invalid
|
|
response.Default(400, `Invalid JSON payload`)
|
|
return true
|
|
end if
|
|
|
|
videoId = payload.videoId
|
|
playlistId = payload.playlistId
|
|
if StringUtils.IsNullOrEmpty(videoId) and StringUtils.IsNullOrEmpty(playlistId)
|
|
response.Default(400, `Missing "videoId" or "playlistId" in payload`)
|
|
return true
|
|
end if
|
|
|
|
instance = m.invidiousService.GetInstance()
|
|
|
|
contentNode = InvidiousContent.ToRowCellContentNode(payload, instance)
|
|
|
|
nodeType = contentNode.type
|
|
if nodeType = "playlist"
|
|
m.videoQueueNode.addToQueuePlaylist = contentNode
|
|
else if nodeType = "video"
|
|
m.videoQueueNode.addToQueue = [contentNode]
|
|
end if
|
|
|
|
response.Default(204, "OK")
|
|
return true
|
|
end function
|
|
|
|
@post("/api/queue/play")
|
|
function Play(context as object) as boolean
|
|
request = context.request
|
|
response = context.response
|
|
|
|
payload = request.Json()
|
|
if payload = invalid
|
|
response.Default(400, `Invalid JSON payload`)
|
|
return true
|
|
end if
|
|
|
|
videoId = payload.videoId
|
|
playlistId = payload.playlistId
|
|
if StringUtils.IsNullOrEmpty(videoId) and StringUtils.IsNullOrEmpty(playlistId)
|
|
response.Default(400, `Missing "videoId" or "playlistId" in payload`)
|
|
return true
|
|
end if
|
|
|
|
if IsString(payload.timestamp)
|
|
payload.timestamp = payload.timestamp.toInt()
|
|
end if
|
|
|
|
instance = m.invidiousService.GetInstance()
|
|
|
|
contentNode = InvidiousContent.ToRowCellContentNode(payload, instance)
|
|
nodeType = contentNode.type
|
|
|
|
if nodeType = "playlist"
|
|
playlistIndex = MathUtils.Max(0, ValidInt(payload.playlistIndex))
|
|
|
|
m.videoQueueNode.playPlaylist = {
|
|
playlistNode: contentNode
|
|
playlistIndex: playlistIndex
|
|
}
|
|
else if nodeType = "video"
|
|
m.videoQueueNode.playVideo = contentNode
|
|
end if
|
|
|
|
response.Default(204, "OK")
|
|
return true
|
|
end function
|
|
|
|
@delete("/api/queue")
|
|
function ClearQueue(context as object) as boolean
|
|
response = context.response
|
|
|
|
m.videoQueueNode.clearQueue = true
|
|
|
|
response.Default(204, "OK")
|
|
return true
|
|
end function
|
|
|
|
end class
|
|
|
|
end namespace
|