feat: update custom nodes to latest hash
This commit is contained in:
parent
68b4d93639
commit
84802f5c4e
@ -53,9 +53,8 @@ import {
|
||||
Plus,
|
||||
} from "lucide-react";
|
||||
import * as React from "react";
|
||||
import { toast } from "sonner";
|
||||
import useSWR from "swr";
|
||||
import { z } from "zod";
|
||||
import { getBranchInfo } from "./getBranchInfo";
|
||||
|
||||
export function SnapshotPickerView({
|
||||
field,
|
||||
@ -131,7 +130,7 @@ export function SnapshotPickerView({
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent>
|
||||
<DropdownMenuItem
|
||||
disabled={key.endsWith("comfyui-deploy.git")}
|
||||
disabled={key.endsWith("comfyui-deploy")}
|
||||
// className="opacity-50"
|
||||
onClick={() => {
|
||||
const newNodeList = {
|
||||
@ -148,6 +147,29 @@ export function SnapshotPickerView({
|
||||
>
|
||||
Delete
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
// className="opacity-50"
|
||||
onClick={async () => {
|
||||
const newNodeList = {
|
||||
...field.value.git_custom_nodes,
|
||||
};
|
||||
|
||||
const branchInfo = await getBranchInfo(key);
|
||||
|
||||
if (!branchInfo) return;
|
||||
|
||||
newNodeList[key].hash = branchInfo?.commit.sha;
|
||||
|
||||
const nodeList = newNodeList;
|
||||
const newValue = {
|
||||
...field.value,
|
||||
git_custom_nodes: nodeList,
|
||||
};
|
||||
field.onChange(newValue);
|
||||
}}
|
||||
>
|
||||
Update
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</Card>
|
||||
@ -268,24 +290,6 @@ type CustomNodeList = {
|
||||
}[];
|
||||
};
|
||||
|
||||
const RepoSchema = z.object({
|
||||
default_branch: z.string(),
|
||||
});
|
||||
|
||||
const BranchInfoSchema = z.object({
|
||||
commit: z.object({
|
||||
sha: z.string(),
|
||||
}),
|
||||
});
|
||||
|
||||
function extractRepoName(repoUrl: string) {
|
||||
const url = new URL(repoUrl);
|
||||
const pathParts = url.pathname.split("/");
|
||||
const repoName = pathParts[2].replace(".git", "");
|
||||
const author = pathParts[1];
|
||||
return `${author}/${repoName}`;
|
||||
}
|
||||
|
||||
function CustomNodesSelector({
|
||||
field,
|
||||
}: Pick<AutoFormInputComponentProps, "field">) {
|
||||
@ -362,43 +366,7 @@ function CustomNodesSelector({
|
||||
delete newNodeList[currentValue];
|
||||
nodeList = newNodeList;
|
||||
} 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);
|
||||
const branchInfo = await getBranchInfo(currentValue);
|
||||
|
||||
if (!branchInfo) return;
|
||||
|
||||
|
52
web/src/components/custom-form/getBranchInfo.tsx
Normal file
52
web/src/components/custom-form/getBranchInfo.tsx
Normal file
@ -0,0 +1,52 @@
|
||||
import { toast } from "sonner";
|
||||
import { z } from "zod";
|
||||
|
||||
const RepoSchema = z.object({
|
||||
default_branch: z.string(),
|
||||
});
|
||||
const BranchInfoSchema = z.object({
|
||||
commit: z.object({
|
||||
sha: z.string(),
|
||||
}),
|
||||
});
|
||||
function extractRepoName(repoUrl: string) {
|
||||
const url = new URL(repoUrl);
|
||||
const pathParts = url.pathname.split("/");
|
||||
const repoName = pathParts[2].replace(".git", "");
|
||||
const author = pathParts[1];
|
||||
return `${author}/${repoName}`;
|
||||
}
|
||||
export async function getBranchInfo(gitUrl: string) {
|
||||
const repoName = extractRepoName(gitUrl);
|
||||
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);
|
||||
return branchInfo;
|
||||
}
|
@ -16,7 +16,7 @@ export const insertCustomMachineSchema = createInsertSchema(machinesTable, {
|
||||
schema.snapshot.default({
|
||||
comfyui: "d0165d819afe76bd4e6bdd710eb5f3e571b6a804",
|
||||
git_custom_nodes: {
|
||||
"https://github.com/BennyKok/comfyui-deploy.git": {
|
||||
"https://github.com/bennykok/comfyui-deploy": {
|
||||
hash: "a838cb7ad425e5652c3931fbafdc886b53c48a22",
|
||||
disabled: false,
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user