return nodeType to mapping instead of set

This commit is contained in:
Weixuan Fu
2024-03-31 19:27:52 +08:00
parent bdfd0b8f2c
commit 237345bf90
2 changed files with 20 additions and 11 deletions
+4 -5
View File
@@ -172,7 +172,7 @@ def get_git_repo(node_type: str):
git_repo = git_repo[:-4]
username = git_repo.split("/")[-2]
repo_name = git_repo.split("/")[-1]
return {"repoID": f"{username}/{repo_name}", "commitHash": commit_hash}
return {"gitRepo": f"{username}/{repo_name}", "commitHash": commit_hash}
@server.PromptServer.instance.routes.post("/workspace/fetch_node_repos") # Handle POST requests
async def fetch_node_repos(request):
@@ -180,14 +180,13 @@ async def fetch_node_repos(request):
nodetypes = data.get("nodes")
if not nodetypes:
return web.Response(status=400, text="NodeTypes parameter is required and should be a list of node types.")
repos = {}
repos_mapping = {}
for nodetype in nodetypes:
try:
repo = get_git_repo(nodetype)
if repo:
repos[repo.get('repoID')] = repo
repos_mapping[nodetype] = repo
except Exception as e:
print(f"Error fetching repo for {nodetype}: {e}")
result = list(repos.values())
return web.Response(text=json.dumps(result), content_type='application/json')
return web.Response(text=json.dumps(repos_mapping), content_type='application/json')
+16 -6
View File
@@ -32,7 +32,7 @@ type ImageFile = {
};
type NodeRepo = {
commitHash: string;
repoID: string;
gitRepo: string;
};
export type DepsResult = {
@@ -114,10 +114,13 @@ export async function extractAndFetchFileNames(
}
},
);
const resp = await fetch("workspace/fetch_node_repos", {
method: "POST",
body: JSON.stringify({ nodes: nodes.map((n) => n.type) }),
})
const reposMapping: Record<string, NodeRepo> = await fetch(
"workspace/fetch_node_repos",
{
method: "POST",
body: JSON.stringify({ nodes: nodes.map((n) => n.type) }),
},
)
.then((res) => {
if (!res.ok) {
return [];
@@ -132,7 +135,14 @@ export async function extractAndFetchFileNames(
const models = await Promise.all(modelPromises);
const modelsMap: Record<string, DepsResultModel> = {};
models.forEach((model) => {
// if (model.nodeType) {
// model.gitRepo = reposMapping[model.nodeType];
// }
modelsMap[model.filename] = model;
});
return { models: modelsMap, images, nodeRepos: resp };
const nodeRepos: Record<string, NodeRepo> = {};
Object.values(reposMapping).forEach((repo) => {
nodeRepos[repo.gitRepo] = repo;
});
return { models: modelsMap, images, nodeRepos: Object.values(nodeRepos) };
}