added list for srsc

This commit is contained in:
Djeeberjr 2023-06-30 16:19:00 +02:00
parent d1f9104aba
commit d2873d6353
4 changed files with 45 additions and 1 deletions

View File

@ -70,5 +70,20 @@ class CLI extends CLIAppBase {
return true;
});
}, "<name>");
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;
});
});
}
}

View File

@ -30,3 +30,7 @@ typedef UnregisterRequest = {
typedef UnregisterResponse = {
public var success:Bool;
}
typedef ListRequest = {
public var ?type:String;
}

View File

@ -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<String> {
return [ for (k in ressources.keys()) k];
}
private function load() {
var store = KVStore.getStoreForClass();
var data:Null<Map<String, NetworkID>> = store.get("ressources");

View File

@ -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<Array<String>> {
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);
}
});
}
}