diff --git a/glob/manager_core.py b/glob/manager_core.py index 67c64769..fe22c5e6 100644 --- a/glob/manager_core.py +++ b/glob/manager_core.py @@ -308,6 +308,25 @@ class ManagedResult: return self +def get_commit_hash(fullpath): + git_head = os.path.join(fullpath, '.git', 'HEAD') + if os.path.exists(git_head): + with open(git_head) as f: + line = f.readline() + + if line.startswith("ref: "): + ref = os.path.join(fullpath, '.git', line[5:].strip()) + if os.path.exists(ref): + with open(ref) as f2: + return f2.readline().strip() + else: + return "unknown" + else: + return line + + return "unknown" + + class UnifiedManager: def __init__(self): self.cnr_inactive_nodes = {} # node_id -> node_version -> fullpath diff --git a/glob/manager_server.py b/glob/manager_server.py index ec1e9d28..b773a448 100644 --- a/glob/manager_server.py +++ b/glob/manager_server.py @@ -542,6 +542,33 @@ def populate_markdown(x): x['title'] = manager_util.sanitize_tag(x['title']) +@routes.get("/customnode/installed") +async def installed_list(request): + result = {} + for x in folder_paths.get_folder_paths('custom_nodes'): + for y in os.listdir(x): + if y.endswith('.disabled') or y == '__pycache__' or y.endswith('.py') or y.endswith('.example'): + continue + + spec = y.split('@') + + if len(spec) == 2: + ver = spec[1].replace('_', '.') + + if ver == 'nightly': + ver = None + else: + ver = None + + # extract commit hash + if ver is None: + ver = core.get_commit_hash(os.path.join(x, y)) + + result[y] = ver + + return web.json_response(result, content_type='application/json') + + @routes.get("/customnode/getlist") async def fetch_customnode_list(request): """