From 592b377ac46ea931bfb6311cced636b1c68f103f Mon Sep 17 00:00:00 2001
From: pythongosssss <125205205+pythongosssss@users.noreply.github.com>
Date: Fri, 3 Mar 2023 19:05:39 +0000
Subject: [PATCH] Added dynamic loading of extensions
---
server.py | 6 ++++++
web/extensions/logging.js.example | 1 +
web/index.html | 3 ---
web/scripts/api.js | 9 +++++++++
web/scripts/app.js | 28 ++++++++++++++++++----------
5 files changed, 34 insertions(+), 13 deletions(-)
diff --git a/server.py b/server.py
index cfc103cb..64b2f70a 100644
--- a/server.py
+++ b/server.py
@@ -5,6 +5,7 @@ import nodes
import execution
import uuid
import json
+import glob
try:
import aiohttp
@@ -52,6 +53,11 @@ class PromptServer():
async def get_root(request):
return web.FileResponse(os.path.join(self.web_root, "index.html"))
+ @routes.get("/extensions")
+ async def get_extensions(request):
+ files = glob.glob(os.path.join(self.web_root, 'extensions/**/*.js'), recursive=True)
+ return web.json_response(list(map(lambda f: "/" + os.path.relpath(f, self.web_root).replace("\\", "/"), files)))
+
@routes.get("/view/{file}")
async def view_image(request):
if "file" in request.match_info:
diff --git a/web/extensions/logging.js.example b/web/extensions/logging.js.example
index ce0b346e..d015096a 100644
--- a/web/extensions/logging.js.example
+++ b/web/extensions/logging.js.example
@@ -1,6 +1,7 @@
import { app } from "../scripts/app.js";
const ext = {
+ // Unique name for the extension
name: "Example.LoggingExtension",
async init(app) {
// Any initial setup to run as soon as the page loads
diff --git a/web/index.html b/web/index.html
index 1236d754..cd95594f 100644
--- a/web/index.html
+++ b/web/index.html
@@ -6,9 +6,6 @@