From d2873d635342248a9d1592b76e01f35d6a0de96a Mon Sep 17 00:00:00 2001 From: Djeeberjr Date: Fri, 30 Jun 2023 16:19:00 +0200 Subject: [PATCH] added list for srsc --- src/bin/srsc/CLI.hx | 15 +++++++++++++++ src/bin/srsc/PackageTypes.hx | 4 ++++ src/bin/srsc/SiteRessourceController.hx | 6 ++++++ src/lib/RessourceNames.hx | 21 ++++++++++++++++++++- 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/bin/srsc/CLI.hx b/src/bin/srsc/CLI.hx index 8cb832f..8a27fa8 100644 --- a/src/bin/srsc/CLI.hx +++ b/src/bin/srsc/CLI.hx @@ -70,5 +70,20 @@ class CLI extends CLIAppBase { return true; }); }, ""); + + registerAsyncSubcommand("list", (args) -> { + return RessourceNames.list().map((res) -> { + switch (res) { + case Success(data): + for (name in data) { + handle.writeLine(name); + } + case Failure(error): + handle.writeLine("Error: " + error); + } + + return true; + }); + }); } } diff --git a/src/bin/srsc/PackageTypes.hx b/src/bin/srsc/PackageTypes.hx index dddbd14..eb27dd9 100644 --- a/src/bin/srsc/PackageTypes.hx +++ b/src/bin/srsc/PackageTypes.hx @@ -30,3 +30,7 @@ typedef UnregisterRequest = { typedef UnregisterResponse = { public var success:Bool; } + +typedef ListRequest = { + public var ?type:String; +} diff --git a/src/bin/srsc/SiteRessourceController.hx b/src/bin/srsc/SiteRessourceController.hx index 25e675d..c42eb97 100644 --- a/src/bin/srsc/SiteRessourceController.hx +++ b/src/bin/srsc/SiteRessourceController.hx @@ -43,6 +43,8 @@ class SiteRessourceController implements Process { pkg.respond(handleUnregister(cast pkg.data)); case "get": pkg.respond(handleGet(cast pkg.data)); + case "list": + pkg.respond(list()); default: handle.writeLine("Unknown message type: " + pkg.data.type); } @@ -84,6 +86,10 @@ class SiteRessourceController implements Process { return ressources.get(name); } + private inline function list():Array { + return [ for (k in ressources.keys()) k]; + } + private function load() { var store = KVStore.getStoreForClass(); var data:Null> = store.get("ressources"); diff --git a/src/lib/RessourceNames.hx b/src/lib/RessourceNames.hx index 35a91b2..74128d4 100644 --- a/src/lib/RessourceNames.hx +++ b/src/lib/RessourceNames.hx @@ -1,8 +1,8 @@ package lib; +import bin.srsc.PackageTypes.ListRequest; import kernel.KernelSettings; import bin.srsc.PackageTypes.UnregisterRequest; -import kernel.log.Log; import bin.srsc.PackageTypes.RegisterRequest; import bin.srsc.PackageTypes.GetRequest; import bin.srsc.SiteRessourceController; @@ -62,4 +62,23 @@ class RessourceNames { payload ); } + + public static function list(controllerID: NetworkID = -1): Promise> { + if (controllerID == -1) controllerID = KernelSettings.siteController; + + var payload: ListRequest = {type: "list"}; + + return Net.instance.sendAndAwait( + controllerID, + SiteRessourceController.SITE_CONTROLLER_RESSOURCE_MANAGER_PROTO, + payload + ).map(res->{ + switch (res){ + case Success(pkg): + return Success(pkg.data); + case Failure(error): + return Failure(error); + } + }); + } } \ No newline at end of file