feat: add clone machine code
This commit is contained in:
parent
b094fcf4b4
commit
ad977f56f3
@ -1,9 +1,8 @@
|
|||||||
import { ButtonAction } from "@/components/ButtonActionLoader";
|
import { ButtonActionMenu } from "@/components/ButtonActionLoader";
|
||||||
import {
|
import {
|
||||||
PublicRunOutputs,
|
PublicRunOutputs,
|
||||||
RunWorkflowInline,
|
RunWorkflowInline,
|
||||||
} from "@/components/VersionSelect";
|
} from "@/components/VersionSelect";
|
||||||
import { Button } from "@/components/ui/button";
|
|
||||||
import {
|
import {
|
||||||
Card,
|
Card,
|
||||||
CardContent,
|
CardContent,
|
||||||
@ -16,7 +15,11 @@ import { usersTable } from "@/db/schema";
|
|||||||
import { getInputsFromWorkflow } from "@/lib/getInputsFromWorkflow";
|
import { getInputsFromWorkflow } from "@/lib/getInputsFromWorkflow";
|
||||||
import { getRelativeTime } from "@/lib/getRelativeTime";
|
import { getRelativeTime } from "@/lib/getRelativeTime";
|
||||||
import { setInitialUserData } from "@/lib/setInitialUserData";
|
import { setInitialUserData } from "@/lib/setInitialUserData";
|
||||||
import { cloneWorkflow, findSharedDeployment } from "@/server/curdDeploments";
|
import {
|
||||||
|
cloneMachine,
|
||||||
|
cloneWorkflow,
|
||||||
|
findSharedDeployment,
|
||||||
|
} from "@/server/curdDeploments";
|
||||||
import { auth, clerkClient } from "@clerk/nextjs/server";
|
import { auth, clerkClient } from "@clerk/nextjs/server";
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
@ -63,13 +66,20 @@ export default async function Page({
|
|||||||
{" / "}
|
{" / "}
|
||||||
{sharedDeployment.workflow.name}
|
{sharedDeployment.workflow.name}
|
||||||
</div>
|
</div>
|
||||||
<Button asChild className="gap-2" variant="outline" type="submit">
|
|
||||||
<ButtonAction
|
<ButtonActionMenu
|
||||||
action={cloneWorkflow.bind(null, sharedDeployment.id)}
|
title="Clone"
|
||||||
>
|
actions={[
|
||||||
Clone
|
{
|
||||||
</ButtonAction>
|
title: "Workflow",
|
||||||
</Button>
|
action: cloneWorkflow.bind(null, sharedDeployment.id),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Machine",
|
||||||
|
action: cloneMachine.bind(null, sharedDeployment.id),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
</CardTitle>
|
</CardTitle>
|
||||||
<CardDescription suppressHydrationWarning={true}>
|
<CardDescription suppressHydrationWarning={true}>
|
||||||
{getRelativeTime(sharedDeployment?.updated_at)}
|
{getRelativeTime(sharedDeployment?.updated_at)}
|
||||||
|
@ -2,6 +2,14 @@
|
|||||||
|
|
||||||
import { LoadingIcon } from "@/components/LoadingIcon";
|
import { LoadingIcon } from "@/components/LoadingIcon";
|
||||||
import { callServerPromise } from "@/components/callServerPromise";
|
import { callServerPromise } from "@/components/callServerPromise";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuItem,
|
||||||
|
DropdownMenuTrigger,
|
||||||
|
} from "@/components/ui/dropdown-menu";
|
||||||
|
import { MoreVertical } from "lucide-react";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
|
||||||
@ -33,3 +41,38 @@ export function ButtonAction({
|
|||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function ButtonActionMenu(props: {
|
||||||
|
title?: string;
|
||||||
|
actions: {
|
||||||
|
title: string;
|
||||||
|
action: () => Promise<any>;
|
||||||
|
}[];
|
||||||
|
}) {
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button className="gap-2" variant="outline" disabled={isLoading}>
|
||||||
|
{props.title}
|
||||||
|
{isLoading ? <LoadingIcon /> : <MoreVertical size={14} />}
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent className="w-56">
|
||||||
|
{props.actions.map((action) => (
|
||||||
|
<DropdownMenuItem
|
||||||
|
key={action.title}
|
||||||
|
onClick={async () => {
|
||||||
|
setIsLoading(true);
|
||||||
|
await callServerPromise(action.action());
|
||||||
|
setIsLoading(false);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{action.title}
|
||||||
|
</DropdownMenuItem>
|
||||||
|
))}
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
@ -4,6 +4,7 @@ import { db } from "@/db/db";
|
|||||||
import type { DeploymentType } from "@/db/schema";
|
import type { DeploymentType } from "@/db/schema";
|
||||||
import { deploymentsTable, workflowTable } from "@/db/schema";
|
import { deploymentsTable, workflowTable } from "@/db/schema";
|
||||||
import { createNewWorkflow } from "@/server/createNewWorkflow";
|
import { createNewWorkflow } from "@/server/createNewWorkflow";
|
||||||
|
import { addCustomMachine } from "@/server/curdMachine";
|
||||||
import { withServerPromise } from "@/server/withServerPromise";
|
import { withServerPromise } from "@/server/withServerPromise";
|
||||||
import { auth } from "@clerk/nextjs";
|
import { auth } from "@clerk/nextjs";
|
||||||
import { and, eq, isNull } from "drizzle-orm";
|
import { and, eq, isNull } from "drizzle-orm";
|
||||||
@ -162,3 +163,35 @@ export const cloneWorkflow = withServerPromise(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const cloneMachine = withServerPromise(async (deployment_id: string) => {
|
||||||
|
const deployment = await db.query.deploymentsTable.findFirst({
|
||||||
|
where: and(
|
||||||
|
eq(deploymentsTable.environment, "public-share"),
|
||||||
|
eq(deploymentsTable.id, deployment_id)
|
||||||
|
),
|
||||||
|
with: {
|
||||||
|
machine: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!deployment) throw new Error("No deployment found");
|
||||||
|
if (deployment.machine.type !== "comfy-deploy-serverless")
|
||||||
|
throw new Error("Can only clone comfy-deploy-serverlesss");
|
||||||
|
|
||||||
|
const { userId, orgId } = auth();
|
||||||
|
|
||||||
|
if (!userId) throw new Error("No user id");
|
||||||
|
|
||||||
|
await addCustomMachine({
|
||||||
|
gpu: deployment.machine.gpu,
|
||||||
|
models: deployment.machine.models,
|
||||||
|
snapshot: deployment.machine.snapshot,
|
||||||
|
name: `${deployment.machine.name} (Cloned)`,
|
||||||
|
type: "comfy-deploy-serverless",
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
message: "Successfully cloned workflow",
|
||||||
|
};
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user