feat: add clone machine code
This commit is contained in:
@@ -4,6 +4,7 @@ import { db } from "@/db/db";
|
||||
import type { DeploymentType } from "@/db/schema";
|
||||
import { deploymentsTable, workflowTable } from "@/db/schema";
|
||||
import { createNewWorkflow } from "@/server/createNewWorkflow";
|
||||
import { addCustomMachine } from "@/server/curdMachine";
|
||||
import { withServerPromise } from "@/server/withServerPromise";
|
||||
import { auth } from "@clerk/nextjs";
|
||||
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",
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user