feat: endpoint customnode/installed is added

This commit is contained in:
Dr.Lt.Data 2024-12-19 18:13:10 +09:00
parent 95ee037a44
commit 9b5adfeb2c
2 changed files with 46 additions and 0 deletions

View File

@ -308,6 +308,25 @@ class ManagedResult:
return self 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: class UnifiedManager:
def __init__(self): def __init__(self):
self.cnr_inactive_nodes = {} # node_id -> node_version -> fullpath self.cnr_inactive_nodes = {} # node_id -> node_version -> fullpath

View File

@ -542,6 +542,33 @@ def populate_markdown(x):
x['title'] = manager_util.sanitize_tag(x['title']) 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") @routes.get("/customnode/getlist")
async def fetch_customnode_list(request): async def fetch_customnode_list(request):
""" """