feat: add pip modules when selecting custom_nodes

This commit is contained in:
bennykok 2024-01-26 17:02:55 +08:00
parent 78721b3129
commit 2bace09f5e

View File

@ -157,6 +157,7 @@ type CustomNodeList = {
author: string; author: string;
title: string; title: string;
reference: string; reference: string;
pip: string[];
files: string[]; files: string[];
install_type: string; install_type: string;
description: string; description: string;
@ -237,56 +238,12 @@ function CustomNodesSelector({
key={index} key={index}
value={framework.reference} value={framework.reference}
onSelect={async (currentValue) => { onSelect={async (currentValue) => {
const repoName = extractRepoName(currentValue);
console.log(repoName);
const id = toast.loading(`Fetching repo info...`);
// toast.info("hi");
const repo = await fetch(
`https://api.github.com/repos/${repoName}`
)
.then((x) => x.json())
.then((x) => {
console.log(x);
return x;
})
.then((x) => RepoSchema.parse(x))
.catch((e) => {
console.error(e);
toast.dismiss(id);
toast.error(`Failed to fetch repo info ${e.message}`);
return null;
});
if (!repo) return;
const branch = repo.default_branch;
const branchInfo = await fetch(
`https://api.github.com/repos/${repoName}/branches/${branch}`
)
.then((x) => x.json())
.then((x) => BranchInfoSchema.parse(x))
.catch((e) => {
console.error(e);
toast.dismiss(id);
toast.error(
`Failed to fetch branch info ${e.message}`
);
return null;
});
toast.dismiss(id);
if (!branchInfo) return;
let nodeList: Record< let nodeList: Record<
string, string,
{ {
hash: string; hash: string;
disabled: boolean; disabled: boolean;
pip?: string[]
} }
>; >;
const x = customNodeList; const x = customNodeList;
@ -296,10 +253,49 @@ function CustomNodesSelector({
delete newNodeList[currentValue]; delete newNodeList[currentValue];
nodeList = newNodeList; nodeList = newNodeList;
} else { } else {
const repoName = extractRepoName(currentValue);
const id = toast.loading(`Fetching repo info...`);
const repo = await fetch(
`https://api.github.com/repos/${repoName}`
)
.then((x) => x.json())
.then((x) => {
console.log(x);
return x;
})
.then((x) => RepoSchema.parse(x))
.catch((e) => {
console.error(e);
toast.dismiss(id);
toast.error(`Failed to fetch repo info ${e.message}`);
return null;
});
if (!repo) return;
const branch = repo.default_branch;
const branchInfo = await fetch(
`https://api.github.com/repos/${repoName}/branches/${branch}`
)
.then((x) => x.json())
.then((x) => BranchInfoSchema.parse(x))
.catch((e) => {
console.error(e);
toast.dismiss(id);
toast.error(
`Failed to fetch branch info ${e.message}`
);
return null;
});
toast.dismiss(id);
if (!branchInfo) return;
nodeList = { nodeList = {
[currentValue]: { [currentValue]: {
hash: branchInfo?.commit.sha, hash: branchInfo?.commit.sha,
disabled: false, disabled: false,
pip: framework.pip
}, },
...x, ...x,
}; };