Files
playlet-piped/playlet-lib/src/components/Web/PlayletWebServer/Middleware/PlayletLibUrlsRouter.bs
T
Brahim Hadricheandgithub-action linter d70a07049a Add Job System (#656)
* Add Job System

* Remove testing stuff

* changelog

* plugin work

* Convert a couple more jobs

* simplify callback

* assert

* Logging changes and rendezvous perf

* changelog

* sb segment viewed job

* clear cache, and few changes

* Lint fix

* a couple more jobs

* reduce rendezvous in web server

* refactor

* Lint fix

* no message

* test shutdown

* comment

* free fields

---------

Co-authored-by: github-action linter <githubaction@githubaction.com>
2025-06-17 20:13:48 -04:00

73 lines
2.2 KiB
Plaintext

import "pkg:/components/Web/WebServer/Http/HttpRouter.bs"
import "pkg:/source/utils/RegistryUtils.bs"
import "pkg:/source/utils/StringUtils.bs"
import "pkg:/source/utils/Types.bs"
namespace Http
class PlayletLibUrlsRouter extends HttpRouter
function new(server as object)
super()
m.scene = server.task.getScene()
end function
@get("/api/playlet-lib-urls")
function GetPlayletLibUrls(context as object) as boolean
response = context.response
saved = RegistryUtils.Read(RegistryUtils.PLAYLET_LIB_URLS)
if saved <> invalid
saved = ParseJson(saved)
end if
response.Json({
loaded: m.scene.playletLibLoadedUrl
saved: saved
})
return true
end function
@post("/api/playlet-lib-urls")
function SetPlayletLibUrls(context as object) as boolean
request = context.request
response = context.response
payload = request.Json()
if payload = invalid or not IsArray(payload)
response.Default(400, "Invalid payload")
return true
end if
if payload.Count() = 0
response.Default(400, "Payload must contain at least one item")
return true
end if
for each item in payload
if StringUtils.IsNullOrEmpty(item.link) or StringUtils.IsNullOrEmpty(item.type)
response.Default(400, `Invalid item in array (must have "link" and "type" properties)`)
return true
end if
end for
RegistryUtils.Write(RegistryUtils.PLAYLET_LIB_URLS, request.body)
response.Default(204, "OK")
return true
end function
@delete("/api/playlet-lib-urls")
function DeletePlayletLibUrls(context as object) as boolean
response = context.response
RegistryUtils.Delete(RegistryUtils.PLAYLET_LIB_URLS)
response.Default(204, "OK")
return true
end function
end class
end namespace