feat: add clone machine code

This commit is contained in:
BennyKok
2024-01-18 19:50:41 +08:00
parent b094fcf4b4
commit ad977f56f3
3 changed files with 96 additions and 10 deletions
+33
View File
@@ -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",
};
});