Added support for static assets, remove frontend_bundle field

This commit is contained in:
Jonas Dellinger
2022-05-25 21:35:03 +02:00
parent 74438a3145
commit d23f1ac56c
2 changed files with 8 additions and 2 deletions
+8 -1
View File
@@ -76,6 +76,7 @@ class Loader:
web.get("/plugins", self.handle_plugins),
web.get("/plugins/{plugin_name}/frontend_bundle", self.handle_frontend_bundle),
web.post("/plugins/{plugin_name}/methods/{method_name}", self.handle_plugin_method_call),
web.get("/plugins/{plugin_name}/assets/{path:.*}", self.handle_frontend_assets),
web.post("/methods/{method_name}", self.handle_server_method_call)
])
@@ -83,10 +84,16 @@ class Loader:
plugins = list(map(lambda kv: dict([("name", kv[0])]), self.plugins.items()))
return web.json_response(plugins)
def handle_frontend_assets(self, request):
plugin = self.plugins[request.match_info["plugin_name"]]
file = path.join(self.plugin_path, plugin.plugin_directory, "dist/assets", request.match_info["path"])
return web.FileResponse(file)
def handle_frontend_bundle(self, request):
plugin = self.plugins[request.match_info["plugin_name"]]
with open(path.join(self.plugin_path, plugin.plugin_directory, plugin.frontend_bundle), 'r') as bundle:
with open(path.join(self.plugin_path, plugin.plugin_directory, "dist/index.js"), 'r') as bundle:
return web.Response(text=bundle.read(), content_type="application/javascript")
def import_plugin(self, file, plugin_directory, refresh=False):
-1
View File
@@ -26,7 +26,6 @@ class PluginWrapper:
self.name = json["name"]
self.author = json["author"]
self.frontend_bundle = json["frontend_bundle"]
self.flags = json["flags"]
self.passive = not path.isfile(self.file)