refactor: move workflow to /workflow

This commit is contained in:
BennyKok 2023-12-14 22:50:28 +08:00
parent 7e05fae7b3
commit c419e10827
6 changed files with 33 additions and 24 deletions

View File

@ -2,7 +2,7 @@ import { NextResponse, type NextRequest } from "next/server";
export async function GET(request: NextRequest) { export async function GET(request: NextRequest) {
const file = new URL(request.url).searchParams.get("file"); const file = new URL(request.url).searchParams.get("file");
console.log(file); console.log(`${process.env.SPACES_ENDPOINT}/comfyui-deploy/${file}`);
return NextResponse.redirect( return NextResponse.redirect(
`${process.env.SPACES_ENDPOINT}/comfyui-deploy/${file}` `${process.env.SPACES_ENDPOINT}/comfyui-deploy/${file}`
); );

View File

@ -1,5 +1,5 @@
import { DeploymentsTable, RunsTable } from "../../components/RunsTable"; import { DeploymentsTable, RunsTable } from "../../../components/RunsTable";
import { findFirstTableWithVersion } from "../../server/findFirstTableWithVersion"; import { findFirstTableWithVersion } from "../../../server/findFirstTableWithVersion";
import { MachinesWSMain } from "@/components/MachinesWS"; import { MachinesWSMain } from "@/components/MachinesWS";
import { import {
CreateDeploymentButton, CreateDeploymentButton,
@ -49,7 +49,7 @@ export default async function Page({
<MachinesWSMain machines={machines} /> <MachinesWSMain machines={machines} />
</CardContent> </CardContent>
</Card> </Card>
<Card className="w-full "> <Card className="w-full h-fit">
<CardHeader> <CardHeader>
<CardTitle>Deployments</CardTitle> <CardTitle>Deployments</CardTitle>
</CardHeader> </CardHeader>
@ -60,7 +60,7 @@ export default async function Page({
</Card> </Card>
</div> </div>
<Card className="w-full "> <Card className="w-full h-fit">
<CardHeader> <CardHeader>
<CardTitle>Run</CardTitle> <CardTitle>Run</CardTitle>
</CardHeader> </CardHeader>

View File

@ -21,28 +21,32 @@ curl --request POST \
}' }'
`; `;
const curlTemplate_checkStatus = `
curl --request GET \
--url 'http://localhost:3000/api/run?run_id=xxx' \
--header 'Content-Type: application/json'
`;
const jsTemplate = ` const jsTemplate = `
const options = { fetch('<URL>', {
method: 'POST', method: 'POST',
headers: {'Content-Type': 'application/json'}, headers: {'Content-Type': 'application/json'},
body: '{"deployment_id":"<ID>"}' body: JSON.stringify({
}; deployment_id: '<ID>',
}),
fetch('<URL>', options) })
.then(response => response.json()) .then(response => response.json())
.then(response => console.log(response)) .then(response => console.log(response))
.catch(err => console.error(err)); .catch(err => console.error(err));
`; `;
const jsTemplate_checkStatus = ` const jsTemplate_checkStatus = `
const options = {
method: 'GET',
headers: {'Content-Type': 'application/json'},
};
const run_id = '<RUN_ID>'; const run_id = '<RUN_ID>';
fetch('<URL>?run_id=' + run_id, options) fetch('<URL>?run_id=' + run_id, {
method: 'GET',
headers: {'Content-Type': 'application/json'},
})
.then(response => response.json()) .then(response => response.json())
.then(response => console.log(response)) .then(response => console.log(response))
.catch(err => console.error(err)); .catch(err => console.error(err));
@ -82,17 +86,23 @@ export function DeploymentDisplay({
<TabsTrigger value="curl">curl</TabsTrigger> <TabsTrigger value="curl">curl</TabsTrigger>
</TabsList> </TabsList>
<TabsContent className="flex flex-col gap-2" value="js"> <TabsContent className="flex flex-col gap-2" value="js">
Trigger the workflow
<CodeBlock lang="js" code={formatCode(jsTemplate, deployment)} /> <CodeBlock lang="js" code={formatCode(jsTemplate, deployment)} />
Check the status of the run, and retrieve the outputs
<CodeBlock <CodeBlock
lang="js" lang="js"
code={formatCode(jsTemplate_checkStatus, deployment)} code={formatCode(jsTemplate_checkStatus, deployment)}
/> />
</TabsContent> </TabsContent>
<TabsContent value="curl"> <TabsContent className="flex flex-col gap-2" value="curl">
<CodeBlock <CodeBlock
lang="bash" lang="bash"
code={formatCode(curlTemplate, deployment)} code={formatCode(curlTemplate, deployment)}
/> />
<CodeBlock
lang="bash"
code={formatCode(curlTemplate_checkStatus, deployment)}
/>
</TabsContent> </TabsContent>
</Tabs> </Tabs>
</DialogContent> </DialogContent>

View File

@ -70,7 +70,7 @@ export function OutputRender(props: { run_id: string; filename: string }) {
return ( return (
<img <img
alt={props.filename} alt={props.filename}
src={`api/view?file=${encodeURIComponent( src={`/api/view?file=${encodeURIComponent(
`outputs/runs/${props.run_id}/${props.filename}` `outputs/runs/${props.run_id}/${props.filename}`
)}`} )}`}
/> />

View File

@ -23,7 +23,7 @@ export function RunOutputs({ run_id }: { run_id: string }) {
// .then((x) => x.json()) // .then((x) => x.json())
// .then((x) => setOutputs(x)); // .then((x) => setOutputs(x));
callServerPromise(getRunsOutput(run_id).then((x) => setOutputs(x))); callServerPromise(getRunsOutput(run_id).then((x) => setOutputs(x)));
}, [run_id, outputs]); }, [run_id]);
return ( return (
<Table> <Table>

View File

@ -9,7 +9,6 @@ import {
DropdownMenuContent, DropdownMenuContent,
DropdownMenuItem, DropdownMenuItem,
DropdownMenuLabel, DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger, DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"; } from "@/components/ui/dropdown-menu";
import { Input } from "@/components/ui/input"; import { Input } from "@/components/ui/input";
@ -85,7 +84,7 @@ export const columns: ColumnDef<Payment>[] = [
}, },
cell: ({ row }) => { cell: ({ row }) => {
return ( return (
<a className="hover:underline" href={`/${row.original.id}`}> <a className="hover:underline" href={`/workflow/${row.original.id}`}>
{row.getValue("email")} {row.getValue("email")}
</a> </a>
); );
@ -167,7 +166,7 @@ export const columns: ColumnDef<Payment>[] = [
export function WorkflowList({ data }: { data: Payment[] }) { export function WorkflowList({ data }: { data: Payment[] }) {
const [sorting, setSorting] = React.useState<SortingState>([]); const [sorting, setSorting] = React.useState<SortingState>([]);
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>( const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>(
[], []
); );
const [columnVisibility, setColumnVisibility] = const [columnVisibility, setColumnVisibility] =
React.useState<VisibilityState>({}); React.useState<VisibilityState>({});
@ -242,7 +241,7 @@ export function WorkflowList({ data }: { data: Payment[] }) {
? null ? null
: flexRender( : flexRender(
header.column.columnDef.header, header.column.columnDef.header,
header.getContext(), header.getContext()
)} )}
</TableHead> </TableHead>
); );
@ -261,7 +260,7 @@ export function WorkflowList({ data }: { data: Payment[] }) {
<TableCell key={cell.id}> <TableCell key={cell.id}>
{flexRender( {flexRender(
cell.column.columnDef.cell, cell.column.columnDef.cell,
cell.getContext(), cell.getContext()
)} )}
</TableCell> </TableCell>
))} ))}