fix: handle file upload status correctly, add serverless machine type
This commit is contained in:
+41
-18
@@ -7,6 +7,7 @@ import { ComfyAPI_Run } from "@/types/ComfyAPI_Run";
|
||||
import { and, eq } from "drizzle-orm";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import "server-only";
|
||||
import { v4 } from "uuid";
|
||||
|
||||
export const createRun = withServerPromise(
|
||||
async (
|
||||
@@ -37,8 +38,6 @@ export const createRun = withServerPromise(
|
||||
throw new Error("Workflow version not found");
|
||||
}
|
||||
|
||||
const comfyui_endpoint = `${machine.endpoint}/comfyui-deploy/run`;
|
||||
|
||||
const workflow_api = workflow_version_data.workflow_api;
|
||||
|
||||
// Replace the inputs
|
||||
@@ -52,33 +51,57 @@ export const createRun = withServerPromise(
|
||||
}
|
||||
}
|
||||
|
||||
const body = {
|
||||
let prompt_id: string | undefined = undefined;
|
||||
const shareData = {
|
||||
workflow_api: workflow_api,
|
||||
status_endpoint: `${origin}/api/update-run`,
|
||||
file_upload_endpoint: `${origin}/api/file-upload`,
|
||||
};
|
||||
// console.log(body);
|
||||
const bodyJson = JSON.stringify(body);
|
||||
// console.log(bodyJson);
|
||||
|
||||
// Sending to comfyui
|
||||
const _result = await fetch(comfyui_endpoint, {
|
||||
method: "POST",
|
||||
body: bodyJson,
|
||||
cache: "no-store",
|
||||
});
|
||||
|
||||
if (!_result.ok) {
|
||||
throw new Error(`Error creating run, ${_result.statusText}`);
|
||||
switch (machine.type) {
|
||||
case "runpod-serverless":
|
||||
prompt_id = v4();
|
||||
const data = {
|
||||
input: {
|
||||
...shareData,
|
||||
prompt_id: prompt_id,
|
||||
},
|
||||
};
|
||||
console.log(data);
|
||||
const __result = await fetch(`${machine.endpoint}/run`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${machine.auth_token}`,
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
cache: "no-store",
|
||||
});
|
||||
console.log(__result);
|
||||
if (!__result.ok)
|
||||
throw new Error(`Error creating run, ${__result.statusText}`);
|
||||
console.log(data, __result);
|
||||
break;
|
||||
case "classic":
|
||||
const body = shareData;
|
||||
const comfyui_endpoint = `${machine.endpoint}/comfyui-deploy/run`;
|
||||
const _result = await fetch(comfyui_endpoint, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(body),
|
||||
cache: "no-store",
|
||||
});
|
||||
if (!_result.ok)
|
||||
throw new Error(`Error creating run, ${_result.statusText}`);
|
||||
const result = await ComfyAPI_Run.parseAsync(await _result.json());
|
||||
prompt_id = result.prompt_id;
|
||||
break;
|
||||
}
|
||||
|
||||
const result = await ComfyAPI_Run.parseAsync(await _result.json());
|
||||
|
||||
// Add to our db
|
||||
const workflow_run = await db
|
||||
.insert(workflowRunsTable)
|
||||
.values({
|
||||
id: result.prompt_id,
|
||||
id: prompt_id,
|
||||
workflow_id: workflow_version_data.workflow_id,
|
||||
workflow_version_id: workflow_version_data.id,
|
||||
workflow_inputs: inputs,
|
||||
|
||||
Reference in New Issue
Block a user