From d23f1ac56c6749e214303c01adec20f2d4a2d0dd Mon Sep 17 00:00:00 2001 From: Jonas Dellinger Date: Wed, 25 May 2022 21:35:03 +0200 Subject: Added support for static assets, remove frontend_bundle field --- backend/loader.py | 9 ++++++++- backend/plugin.py | 1 - 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/backend/loader.py b/backend/loader.py index e68842e2..9357b4ce 100644 --- a/backend/loader.py +++ b/backend/loader.py @@ -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): diff --git a/backend/plugin.py b/backend/plugin.py index db335225..7d3f36f3 100644 --- a/backend/plugin.py +++ b/backend/plugin.py @@ -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) -- cgit v1.2.3