feat: add custom image inputs
This commit is contained in:
@@ -10,6 +10,7 @@ import { z } from "zod";
|
||||
|
||||
const Request = z.object({
|
||||
deployment_id: z.string(),
|
||||
inputs: z.record(z.string()).optional(),
|
||||
});
|
||||
|
||||
const Request2 = z.object({
|
||||
@@ -48,7 +49,7 @@ export async function POST(request: Request) {
|
||||
|
||||
const origin = new URL(request.url).origin;
|
||||
|
||||
const { deployment_id } = data;
|
||||
const { deployment_id, inputs } = data;
|
||||
|
||||
try {
|
||||
const deploymentData = await db.query.deploymentsTable.findFirst({
|
||||
@@ -60,7 +61,8 @@ export async function POST(request: Request) {
|
||||
const run_id = await createRun(
|
||||
origin,
|
||||
deploymentData.workflow_version_id,
|
||||
deploymentData.machine_id
|
||||
deploymentData.machine_id,
|
||||
inputs
|
||||
);
|
||||
|
||||
return NextResponse.json(
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { replaceCDNUrl } from "@/server/resource";
|
||||
import { NextResponse, type NextRequest } from "next/server";
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
const file = new URL(request.url).searchParams.get("file");
|
||||
console.log(`${process.env.SPACES_ENDPOINT}/comfyui-deploy/${file}`);
|
||||
// console.log(`${process.env.SPACES_ENDPOINT}/comfyui-deploy/${file}`);
|
||||
return NextResponse.redirect(
|
||||
`${process.env.SPACES_ENDPOINT}/comfyui-deploy/${file}`
|
||||
replaceCDNUrl(`${process.env.SPACES_ENDPOINT}/comfyui-deploy/${file}`)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -82,6 +82,7 @@ export const workflowRunsTable = dbSchema.table("workflow_runs", {
|
||||
onDelete: "set null",
|
||||
}
|
||||
),
|
||||
workflow_inputs: jsonb("workflow_inputs").$type<Record<string, string>>(),
|
||||
workflow_id: uuid("workflow_id")
|
||||
.notNull()
|
||||
.references(() => workflowTable.id, {
|
||||
|
||||
@@ -10,7 +10,8 @@ import "server-only";
|
||||
export async function createRun(
|
||||
origin: string,
|
||||
workflow_version_id: string,
|
||||
machine_id: string
|
||||
machine_id: string,
|
||||
inputs?: Record<string, string>
|
||||
) {
|
||||
const machine = await db.query.machinesTable.findFirst({
|
||||
where: eq(workflowRunsTable.id, machine_id),
|
||||
@@ -46,6 +47,15 @@ export async function createRun(
|
||||
|
||||
const comfyui_endpoint = `${machine.endpoint}/comfyui-deploy/run`;
|
||||
|
||||
let workflow_api = workflow_version_data.workflow_api;
|
||||
|
||||
// Replace the inputs
|
||||
if (inputs) {
|
||||
for (const key in inputs) {
|
||||
workflow_api = workflow_api.replace(`"${key}"`, `"${inputs[key]}"`);
|
||||
}
|
||||
}
|
||||
|
||||
// Sending to comfyui
|
||||
const result = await fetch(comfyui_endpoint, {
|
||||
method: "POST",
|
||||
@@ -53,9 +63,10 @@ export async function createRun(
|
||||
// "Content-Type": "application/json",
|
||||
// },
|
||||
body: JSON.stringify({
|
||||
workflow_api: workflow_version_data.workflow_api,
|
||||
workflow_api: workflow_api,
|
||||
status_endpoint: `${origin}/api/update-run`,
|
||||
file_upload_endpoint: `${origin}/api/file-upload`,
|
||||
inputs: inputs,
|
||||
}),
|
||||
}).then(async (res) => ComfyAPI_Run.parseAsync(await res.json()));
|
||||
// .catch((error) => {
|
||||
@@ -79,6 +90,7 @@ export async function createRun(
|
||||
id: result.prompt_id,
|
||||
workflow_id: workflow_version_data.workflow_id,
|
||||
workflow_version_id: workflow_version_data.id,
|
||||
workflow_inputs: inputs,
|
||||
machine_id,
|
||||
})
|
||||
.returning();
|
||||
|
||||
@@ -43,4 +43,7 @@ export async function createDeployments(
|
||||
});
|
||||
}
|
||||
revalidatePath(`/${workflow_id}`);
|
||||
return {
|
||||
message: `Successfully created deployment for ${environment}`,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user