Registry router (#273)
* Registry router * Lint fix --------- Co-authored-by: github-action linter <githubaction@githubaction.com>
This commit is contained in:
1 parent
14cc537032
commit
1078459eb7
6 files changed
+162
-15
No files matched your search
@@ -0,0 +1,49 @@
|
||||
#if DEBUG
|
||||
import "pkg:/source/utils/RegistryUtils.bs"
|
||||
|
||||
namespace Http
|
||||
|
||||
class RegistryRouter extends HttpRouter
|
||||
|
||||
function new()
|
||||
super()
|
||||
end function
|
||||
|
||||
@get("/debug/registry")
|
||||
function GetRegistry(context as object) as boolean
|
||||
response = context.response
|
||||
|
||||
registryValues = RegistryUtils.ReadAll()
|
||||
response.Json(registryValues)
|
||||
return true
|
||||
end function
|
||||
|
||||
@post("/debug/registry")
|
||||
function SetRegistry(context as object) as boolean
|
||||
request = context.request
|
||||
response = context.response
|
||||
|
||||
payload = request.Json()
|
||||
if payload = invalid
|
||||
response.Default(400, "Invalid JSON")
|
||||
return true
|
||||
end if
|
||||
|
||||
RegistryUtils.WriteAll(payload)
|
||||
response.Default(204, "OK")
|
||||
return true
|
||||
end function
|
||||
|
||||
@delete("/debug/registry")
|
||||
function ClearRegistry(context as object) as boolean
|
||||
response = context.response
|
||||
|
||||
RegistryUtils.DeleteAll()
|
||||
response.Default(204, "OK")
|
||||
return true
|
||||
end function
|
||||
|
||||
end class
|
||||
|
||||
end namespace
|
||||
#end if
|
||||
@@ -7,6 +7,7 @@ import "pkg:/components/Web/PlayletWebServer/Middleware/InvidiousRouter.bs"
|
||||
import "pkg:/components/Web/PlayletWebServer/Middleware/PlayletLibUrlsRouter.bs"
|
||||
import "pkg:/components/Web/PlayletWebServer/Middleware/PlayQueueRouter.bs"
|
||||
import "pkg:/components/Web/PlayletWebServer/Middleware/PreferencesRouter.bs"
|
||||
import "pkg:/components/Web/PlayletWebServer/Middleware/RegistryRouter.bs"
|
||||
import "pkg:/components/Web/PlayletWebServer/Middleware/SearchHistoryRouter.bs"
|
||||
import "pkg:/components/Web/PlayletWebServer/Middleware/StateApiRouter.bs"
|
||||
import "pkg:/components/Web/PlayletWebServer/Middleware/ViewRouter.bs"
|
||||
@@ -51,6 +52,8 @@ function SetupRoutes(server as object)
|
||||
server.UseRouter(new Http.HttpStaticFilesRouter("/config", "libpkg:/config", etags, { staticFiles: true }))
|
||||
server.UseRouter(new Http.HttpStaticFilesRouter("/logs", "cachefs:/logs", etags, { fsCheck: true }))
|
||||
#if DEBUG
|
||||
server.UseRouter(new Http.RegistryRouter())
|
||||
|
||||
options = { showDirectories: true, showHidden: true, staticFiles: true }
|
||||
server.UseRouter(new Http.HttpStaticFilesRouter("/debug/libpkg", "libpkg:/", etags, options))
|
||||
options = { showDirectories: true, showHidden: true, fsCheck: true, staticFiles: true }
|
||||
|
||||
@@ -13,24 +13,24 @@ namespace RegistryUtils
|
||||
' "invidious_instances" is deprecated, but we keep for migration purposes
|
||||
const INVIDIOUS_INSTANCES = "invidious_instances"
|
||||
|
||||
function Read(key as string, section = DEFAULT_SECTION as string) as dynamic
|
||||
sec = CreateObject("roRegistrySection", section)
|
||||
if sec.Exists(key)
|
||||
return sec.Read(key)
|
||||
function Read(key as string, sectionName = DEFAULT_SECTION as string) as dynamic
|
||||
section = CreateObject("roRegistrySection", sectionName)
|
||||
if section.Exists(key)
|
||||
return section.Read(key)
|
||||
end if
|
||||
return invalid
|
||||
end function
|
||||
|
||||
function Write(key as string, value as string, section = DEFAULT_SECTION as string)
|
||||
sec = CreateObject("roRegistrySection", section)
|
||||
sec.Write(key, value)
|
||||
sec.Flush()
|
||||
function Write(key as string, value as string, sectionName = DEFAULT_SECTION as string)
|
||||
section = CreateObject("roRegistrySection", sectionName)
|
||||
section.Write(key, value)
|
||||
section.Flush()
|
||||
end function
|
||||
|
||||
function Delete(key as string, section = DEFAULT_SECTION as string)
|
||||
sec = CreateObject("roRegistrySection", section)
|
||||
sec.Delete(key)
|
||||
sec.Flush()
|
||||
function Delete(key as string, sectionName = DEFAULT_SECTION as string)
|
||||
section = CreateObject("roRegistrySection", sectionName)
|
||||
section.Delete(key)
|
||||
section.Flush()
|
||||
end function
|
||||
|
||||
function ReadAll() as object
|
||||
@@ -46,4 +46,22 @@ namespace RegistryUtils
|
||||
return result
|
||||
end function
|
||||
|
||||
function WriteAll(values as object) as void
|
||||
DeleteAll()
|
||||
for each sectionName in values
|
||||
section = CreateObject("roRegistrySection", sectionName)
|
||||
section.WriteMulti(values[sectionName])
|
||||
section.Flush()
|
||||
end for
|
||||
end function
|
||||
|
||||
function DeleteAll() as void
|
||||
registry = CreateObject("roRegistry")
|
||||
sectionNames = registry.GetSectionList()
|
||||
for each sectionName in sectionNames
|
||||
registry.Delete(sectionName)
|
||||
end for
|
||||
registry.Flush()
|
||||
end function
|
||||
|
||||
end namespace
|
||||
Reference in new issue
Block a user