feat: ensure open in comfy ui will carry over the auth token
This commit is contained in:
parent
ac5aba2aa9
commit
8f7f06470c
@ -40,6 +40,7 @@ import {
|
|||||||
updateCustomMachine,
|
updateCustomMachine,
|
||||||
updateMachine,
|
updateMachine,
|
||||||
} from "@/server/curdMachine";
|
} from "@/server/curdMachine";
|
||||||
|
import { editWorkflowOnMachine } from "@/server/editWorkflowOnMachine";
|
||||||
import type {
|
import type {
|
||||||
ColumnDef,
|
ColumnDef,
|
||||||
ColumnFiltersState,
|
ColumnFiltersState,
|
||||||
@ -57,6 +58,7 @@ import {
|
|||||||
import { ArrowUpDown, MoreHorizontal } from "lucide-react";
|
import { ArrowUpDown, MoreHorizontal } from "lucide-react";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
import { toast } from "sonner";
|
||||||
import type { z } from "zod";
|
import type { z } from "zod";
|
||||||
|
|
||||||
export type Machine = MachineType;
|
export type Machine = MachineType;
|
||||||
@ -218,15 +220,22 @@ export const columns: ColumnDef<Machine>[] = [
|
|||||||
{machine.type === "comfy-deploy-serverless" && (
|
{machine.type === "comfy-deploy-serverless" && (
|
||||||
<>
|
<>
|
||||||
<DropdownMenuItem asChild>
|
<DropdownMenuItem asChild>
|
||||||
<a
|
<button
|
||||||
target="_blank"
|
onClick={async () => {
|
||||||
href={machine.endpoint.replace(
|
const id = toast.loading("Getting machine url...")
|
||||||
"comfyui-api",
|
const url = await callServerPromise(
|
||||||
"comfyui-app"
|
editWorkflowOnMachine(machine.id),
|
||||||
)} rel="noreferrer"
|
);
|
||||||
|
if (url && typeof url !== "object") {
|
||||||
|
window.open(url, "_blank");
|
||||||
|
} else if (url && typeof url === "object" && url.error) {
|
||||||
|
console.error(url.error);
|
||||||
|
}
|
||||||
|
toast.dismiss(id)
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
Open ComfyUI
|
Open ComfyUI
|
||||||
</a>
|
</button>
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
@ -402,7 +402,7 @@ export function OpenEditButton({
|
|||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
const url = await callServerPromise(
|
const url = await callServerPromise(
|
||||||
editWorkflowOnMachine(workflow_version_id, machine),
|
editWorkflowOnMachine(machine, workflow_version_id),
|
||||||
);
|
);
|
||||||
if (url && typeof url !== "object") {
|
if (url && typeof url !== "object") {
|
||||||
window.open(url, "_blank");
|
window.open(url, "_blank");
|
||||||
|
@ -9,7 +9,7 @@ import "server-only";
|
|||||||
import { getUrlServerSide } from "./getUrlServerSide";
|
import { getUrlServerSide } from "./getUrlServerSide";
|
||||||
|
|
||||||
export const editWorkflowOnMachine = withServerPromise(
|
export const editWorkflowOnMachine = withServerPromise(
|
||||||
async (workflow_version_id: string, machine_id: string) => {
|
async (machine_id: string, workflow_version_id?: string) => {
|
||||||
const { userId, orgId } = auth();
|
const { userId, orgId } = auth();
|
||||||
|
|
||||||
const domain = getUrlServerSide();
|
const domain = getUrlServerSide();
|
||||||
@ -37,10 +37,18 @@ export const editWorkflowOnMachine = withServerPromise(
|
|||||||
endpoint = machine.endpoint.replace("comfyui-api", "comfyui-app");
|
endpoint = machine.endpoint.replace("comfyui-api", "comfyui-app");
|
||||||
}
|
}
|
||||||
|
|
||||||
return `${endpoint}?workflow_version_id=${encodeURIComponent(
|
const params = {
|
||||||
workflow_version_id,
|
workflow_version_id: workflow_version_id,
|
||||||
)}&auth_token=${encodeURIComponent(token)}&org_display=${encodeURIComponent(
|
auth_token: token,
|
||||||
userName,
|
org_display: userName,
|
||||||
)}&origin=${encodeURIComponent(domain)}`;
|
origin: domain,
|
||||||
|
};
|
||||||
|
|
||||||
|
const queryString = Object.entries(params)
|
||||||
|
.filter(([key, value]) => value !== undefined)
|
||||||
|
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value as string)}`)
|
||||||
|
.join('&');
|
||||||
|
|
||||||
|
return `${endpoint}?${queryString}`;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user