feat: update custom nodes to latest hash
This commit is contained in:
		
							parent
							
								
									68b4d93639
								
							
						
					
					
						commit
						84802f5c4e
					
				@ -53,9 +53,8 @@ import {
 | 
				
			|||||||
  Plus,
 | 
					  Plus,
 | 
				
			||||||
} from "lucide-react";
 | 
					} from "lucide-react";
 | 
				
			||||||
import * as React from "react";
 | 
					import * as React from "react";
 | 
				
			||||||
import { toast } from "sonner";
 | 
					 | 
				
			||||||
import useSWR from "swr";
 | 
					import useSWR from "swr";
 | 
				
			||||||
import { z } from "zod";
 | 
					import { getBranchInfo } from "./getBranchInfo";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function SnapshotPickerView({
 | 
					export function SnapshotPickerView({
 | 
				
			||||||
  field,
 | 
					  field,
 | 
				
			||||||
@ -131,7 +130,7 @@ export function SnapshotPickerView({
 | 
				
			|||||||
                      </DropdownMenuTrigger>
 | 
					                      </DropdownMenuTrigger>
 | 
				
			||||||
                      <DropdownMenuContent>
 | 
					                      <DropdownMenuContent>
 | 
				
			||||||
                        <DropdownMenuItem
 | 
					                        <DropdownMenuItem
 | 
				
			||||||
                          disabled={key.endsWith("comfyui-deploy.git")}
 | 
					                          disabled={key.endsWith("comfyui-deploy")}
 | 
				
			||||||
                          // className="opacity-50"
 | 
					                          // className="opacity-50"
 | 
				
			||||||
                          onClick={() => {
 | 
					                          onClick={() => {
 | 
				
			||||||
                            const newNodeList = {
 | 
					                            const newNodeList = {
 | 
				
			||||||
@ -148,6 +147,29 @@ export function SnapshotPickerView({
 | 
				
			|||||||
                        >
 | 
					                        >
 | 
				
			||||||
                          Delete
 | 
					                          Delete
 | 
				
			||||||
                        </DropdownMenuItem>
 | 
					                        </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>
 | 
					                      </DropdownMenuContent>
 | 
				
			||||||
                    </DropdownMenu>
 | 
					                    </DropdownMenu>
 | 
				
			||||||
                  </Card>
 | 
					                  </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({
 | 
					function CustomNodesSelector({
 | 
				
			||||||
  field,
 | 
					  field,
 | 
				
			||||||
}: Pick<AutoFormInputComponentProps, "field">) {
 | 
					}: Pick<AutoFormInputComponentProps, "field">) {
 | 
				
			||||||
@ -362,43 +366,7 @@ function CustomNodesSelector({
 | 
				
			|||||||
                        delete newNodeList[currentValue];
 | 
					                        delete newNodeList[currentValue];
 | 
				
			||||||
                        nodeList = newNodeList;
 | 
					                        nodeList = newNodeList;
 | 
				
			||||||
                      } else {
 | 
					                      } else {
 | 
				
			||||||
                        const repoName = extractRepoName(currentValue);
 | 
					                        const branchInfo = await getBranchInfo(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;
 | 
					                        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({
 | 
					    schema.snapshot.default({
 | 
				
			||||||
      comfyui: "d0165d819afe76bd4e6bdd710eb5f3e571b6a804",
 | 
					      comfyui: "d0165d819afe76bd4e6bdd710eb5f3e571b6a804",
 | 
				
			||||||
      git_custom_nodes: {
 | 
					      git_custom_nodes: {
 | 
				
			||||||
        "https://github.com/BennyKok/comfyui-deploy.git": {
 | 
					        "https://github.com/bennykok/comfyui-deploy": {
 | 
				
			||||||
          hash: "a838cb7ad425e5652c3931fbafdc886b53c48a22",
 | 
					          hash: "a838cb7ad425e5652c3931fbafdc886b53c48a22",
 | 
				
			||||||
          disabled: false,
 | 
					          disabled: false,
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user