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
+4
-1
@@ -65,6 +65,9 @@
|
|||||||
"generate-sponsorblock-config": "node tools/generate-sponsorblock-config.js",
|
"generate-sponsorblock-config": "node tools/generate-sponsorblock-config.js",
|
||||||
"update-rale-component": "cd tools/RALE && rm TrackerTask.xml && curl -o TrackerTask.zip https://devtools.web.roku.com/roku-advanced-layout-editor/app/TrackerTask.zip && unzip TrackerTask.zip && rm TrackerTask.zip",
|
"update-rale-component": "cd tools/RALE && rm TrackerTask.xml && curl -o TrackerTask.zip https://devtools.web.roku.com/roku-advanced-layout-editor/app/TrackerTask.zip && unzip TrackerTask.zip && rm TrackerTask.zip",
|
||||||
"postinstall": "cd playlet-lib && npm install && cd ../playlet-app && npm install && cd ../playlet-web && npm install",
|
"postinstall": "cd playlet-lib && npm install && cd ../playlet-app && npm install && cd ../playlet-web && npm install",
|
||||||
"update-deps": "npx npm-check-updates -u && cd playlet-app && npx npm-check-updates -u && cd ../playlet-lib && npx npm-check-updates -u && cd ../playlet-web && npx npm-check-updates -u"
|
"update-deps": "npx npm-check-updates -u && cd playlet-app && npx npm-check-updates -u && cd ../playlet-lib && npx npm-check-updates -u && cd ../playlet-web && npx npm-check-updates -u",
|
||||||
|
"registry:write": "node tools/registry.js --input registry.json",
|
||||||
|
"registry:read": "node tools/registry.js --output registry.json",
|
||||||
|
"registry:clear": "node tools/registry.js --clear"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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/PlayletLibUrlsRouter.bs"
|
||||||
import "pkg:/components/Web/PlayletWebServer/Middleware/PlayQueueRouter.bs"
|
import "pkg:/components/Web/PlayletWebServer/Middleware/PlayQueueRouter.bs"
|
||||||
import "pkg:/components/Web/PlayletWebServer/Middleware/PreferencesRouter.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/SearchHistoryRouter.bs"
|
||||||
import "pkg:/components/Web/PlayletWebServer/Middleware/StateApiRouter.bs"
|
import "pkg:/components/Web/PlayletWebServer/Middleware/StateApiRouter.bs"
|
||||||
import "pkg:/components/Web/PlayletWebServer/Middleware/ViewRouter.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("/config", "libpkg:/config", etags, { staticFiles: true }))
|
||||||
server.UseRouter(new Http.HttpStaticFilesRouter("/logs", "cachefs:/logs", etags, { fsCheck: true }))
|
server.UseRouter(new Http.HttpStaticFilesRouter("/logs", "cachefs:/logs", etags, { fsCheck: true }))
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
|
server.UseRouter(new Http.RegistryRouter())
|
||||||
|
|
||||||
options = { showDirectories: true, showHidden: true, staticFiles: true }
|
options = { showDirectories: true, showHidden: true, staticFiles: true }
|
||||||
server.UseRouter(new Http.HttpStaticFilesRouter("/debug/libpkg", "libpkg:/", etags, options))
|
server.UseRouter(new Http.HttpStaticFilesRouter("/debug/libpkg", "libpkg:/", etags, options))
|
||||||
options = { showDirectories: true, showHidden: true, fsCheck: true, staticFiles: true }
|
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
|
' "invidious_instances" is deprecated, but we keep for migration purposes
|
||||||
const INVIDIOUS_INSTANCES = "invidious_instances"
|
const INVIDIOUS_INSTANCES = "invidious_instances"
|
||||||
|
|
||||||
function Read(key as string, section = DEFAULT_SECTION as string) as dynamic
|
function Read(key as string, sectionName = DEFAULT_SECTION as string) as dynamic
|
||||||
sec = CreateObject("roRegistrySection", section)
|
section = CreateObject("roRegistrySection", sectionName)
|
||||||
if sec.Exists(key)
|
if section.Exists(key)
|
||||||
return sec.Read(key)
|
return section.Read(key)
|
||||||
end if
|
end if
|
||||||
return invalid
|
return invalid
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function Write(key as string, value as string, section = DEFAULT_SECTION as string)
|
function Write(key as string, value as string, sectionName = DEFAULT_SECTION as string)
|
||||||
sec = CreateObject("roRegistrySection", section)
|
section = CreateObject("roRegistrySection", sectionName)
|
||||||
sec.Write(key, value)
|
section.Write(key, value)
|
||||||
sec.Flush()
|
section.Flush()
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function Delete(key as string, section = DEFAULT_SECTION as string)
|
function Delete(key as string, sectionName = DEFAULT_SECTION as string)
|
||||||
sec = CreateObject("roRegistrySection", section)
|
section = CreateObject("roRegistrySection", sectionName)
|
||||||
sec.Delete(key)
|
section.Delete(key)
|
||||||
sec.Flush()
|
section.Flush()
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function ReadAll() as object
|
function ReadAll() as object
|
||||||
@@ -46,4 +46,22 @@ namespace RegistryUtils
|
|||||||
return result
|
return result
|
||||||
end function
|
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
|
end namespace
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
// Description: Read, write and delete registry.
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
const { ArgumentParser, BooleanOptionalAction } = require('argparse');
|
||||||
|
const getEnvVars = require('./get-env-vars');
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
const parser = new ArgumentParser({
|
||||||
|
description: 'Manage registry'
|
||||||
|
});
|
||||||
|
|
||||||
|
parser.add_argument('--input', { help: 'Input file path, for importing to Roku device' });
|
||||||
|
parser.add_argument('--output', { help: 'Output file path, for exporting from Roku device' });
|
||||||
|
parser.add_argument('--clear', { help: 'Clear registry', action: BooleanOptionalAction, default: false });
|
||||||
|
|
||||||
|
const args = parser.parse_args();
|
||||||
|
const input = args.input;
|
||||||
|
const output = args.output;
|
||||||
|
const clear = args.clear;
|
||||||
|
|
||||||
|
// only one action can be specified at a time between input, output and clear
|
||||||
|
const actions = [input, output, clear].filter(Boolean);
|
||||||
|
if (actions.length !== 1) {
|
||||||
|
console.error('Only one (and exactly one) action can be specified at a time between --input, --output and --clear');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const config = getEnvVars(['ROKU_DEV_TARGET']);
|
||||||
|
|
||||||
|
const playletServer = `http://${config.ROKU_DEV_TARGET}:8888/debug/registry`;
|
||||||
|
|
||||||
|
if (input) {
|
||||||
|
const registry = JSON.parse(fs.readFileSync(input, { encoding: 'utf8', flag: 'r' }));
|
||||||
|
|
||||||
|
for (const section in registry) {
|
||||||
|
for (const key in registry[section]) {
|
||||||
|
registry[section][key] = JSON.stringify(registry[section][key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await fetch(playletServer, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify(registry),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if (output) {
|
||||||
|
if (fs.existsSync(output)) {
|
||||||
|
throw new Error(`File "${output}" already exists`);
|
||||||
|
}
|
||||||
|
const response = await fetch(playletServer);
|
||||||
|
const registry = await response.json();
|
||||||
|
|
||||||
|
for (const section in registry) {
|
||||||
|
for (const key in registry[section]) {
|
||||||
|
// We expect all values to be JSON strings.
|
||||||
|
// If this changes, we let JSON.parse throw an error.
|
||||||
|
registry[section][key] = JSON.parse(registry[section][key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.writeFileSync(output, JSON.stringify(registry, null, 4));
|
||||||
|
}
|
||||||
|
else if (clear) {
|
||||||
|
await fetch(playletServer, {
|
||||||
|
method: 'DELETE',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.error('No action specified');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
})();
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
// Description: Deploys a test app to a Roku device and waits for it to finish
|
// Description: Deploys a test app to a Roku device and waits for it to finish
|
||||||
// This will log the test report to the console and throw an error if the tests fail
|
// This will log the test report to the console and throw an error if the tests fail
|
||||||
|
|
||||||
const { ArgumentParser } = require('argparse')
|
const { ArgumentParser, BooleanOptionalAction } = require('argparse')
|
||||||
const { BooleanOptionalAction } = require('argparse');
|
|
||||||
const getEnvVars = require('./get-env-vars');
|
const getEnvVars = require('./get-env-vars');
|
||||||
const rokuDeploy = require('roku-deploy');
|
const rokuDeploy = require('roku-deploy');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|||||||
Reference in new issue
Block a user