feat: add create workflow run error server action catch, redirect workflow parse error, add key revoked col
This commit is contained in:
@@ -1,60 +0,0 @@
|
||||
import { parseDataSafe } from "../../../lib/parseDataSafe";
|
||||
import { createRun } from "../../../server/createRun";
|
||||
import { getRunsOutput } from "@/server/getRunsOutput";
|
||||
import { NextResponse } from "next/server";
|
||||
import { z } from "zod";
|
||||
|
||||
const Request = z.object({
|
||||
workflow_version_id: z.string(),
|
||||
machine_id: z.string(),
|
||||
});
|
||||
|
||||
const Request2 = z.object({
|
||||
run_id: z.string(),
|
||||
});
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const [data, error] = await parseDataSafe(Request2, request);
|
||||
if (!data || error) return error;
|
||||
|
||||
const run = await getRunsOutput(data.run_id);
|
||||
|
||||
return NextResponse.json(run, {
|
||||
status: 200,
|
||||
});
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const [data, error] = await parseDataSafe(Request, request);
|
||||
if (!data || error) return error;
|
||||
|
||||
const origin = new URL(request.url).origin;
|
||||
|
||||
const { workflow_version_id, machine_id } = data;
|
||||
|
||||
try {
|
||||
const workflow_run_id = await createRun(
|
||||
origin,
|
||||
workflow_version_id,
|
||||
machine_id
|
||||
);
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
workflow_run_id: workflow_run_id.workflow_run_id,
|
||||
},
|
||||
{
|
||||
status: 200,
|
||||
}
|
||||
);
|
||||
} catch (error: any) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: error.message,
|
||||
},
|
||||
{
|
||||
status: 500,
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import { parseDataSafe } from "../../../lib/parseDataSafe";
|
||||
import { createRun } from "../../../server/createRun";
|
||||
import { db } from "@/db/db";
|
||||
import { deploymentsTable } from "@/db/schema";
|
||||
import { isKeyRevoked } from "@/server/curdApiKeys";
|
||||
import { getRunsData } from "@/server/getRunsOutput";
|
||||
import { parseJWT } from "@/server/parseJWT";
|
||||
import { replaceCDNUrl } from "@/server/resource";
|
||||
@@ -18,14 +19,26 @@ const Request2 = z.object({
|
||||
run_id: z.string(),
|
||||
});
|
||||
|
||||
export async function GET(request: Request) {
|
||||
async function checkToken(request: Request) {
|
||||
const token = request.headers.get("Authorization")?.split(" ")?.[1]; // Assuming token is sent as "Bearer your_token"
|
||||
const userData = token ? parseJWT(token) : undefined;
|
||||
if (!userData) {
|
||||
if (!userData || token === undefined) {
|
||||
return new NextResponse("Invalid or expired token", {
|
||||
status: 401,
|
||||
});
|
||||
} else {
|
||||
const revokedKey = await isKeyRevoked(token);
|
||||
if (revokedKey)
|
||||
return new NextResponse("Revoked token", {
|
||||
status: 401,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const invalidRequest = await checkToken(request)
|
||||
if (invalidRequest) return invalidRequest;
|
||||
|
||||
|
||||
const [data, error] = await parseDataSafe(Request2, request);
|
||||
if (!data || error) return error;
|
||||
@@ -41,7 +54,7 @@ export async function GET(request: Request) {
|
||||
for (let j = 0; j < output.data?.images.length; j++) {
|
||||
const element = output.data?.images[j];
|
||||
element.url = replaceCDNUrl(
|
||||
`${process.env.SPACES_ENDPOINT}/${process.env.SPACES_BUCKET}/outputs/runs/${run.id}/${element.filename}`
|
||||
`${process.env.SPACES_ENDPOINT}/${process.env.SPACES_BUCKET}/outputs/runs/${run.id}/${element.filename}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -53,13 +66,8 @@ export async function GET(request: Request) {
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const token = request.headers.get("Authorization")?.split(" ")?.[1]; // Assuming token is sent as "Bearer your_token"
|
||||
const userData = token ? parseJWT(token) : undefined;
|
||||
if (!userData) {
|
||||
return new NextResponse("Invalid or expired token", {
|
||||
status: 401,
|
||||
});
|
||||
}
|
||||
const invalidRequest = await checkToken(request)
|
||||
if (invalidRequest) return invalidRequest;
|
||||
|
||||
const [data, error] = await parseDataSafe(Request, request);
|
||||
if (!data || error) return error;
|
||||
@@ -79,7 +87,7 @@ export async function POST(request: Request) {
|
||||
origin,
|
||||
deploymentData.workflow_version_id,
|
||||
deploymentData.machine_id,
|
||||
inputs
|
||||
inputs,
|
||||
);
|
||||
|
||||
return NextResponse.json(
|
||||
@@ -88,7 +96,7 @@ export async function POST(request: Request) {
|
||||
},
|
||||
{
|
||||
status: 200,
|
||||
}
|
||||
},
|
||||
);
|
||||
} catch (error: any) {
|
||||
return NextResponse.json(
|
||||
@@ -97,7 +105,7 @@ export async function POST(request: Request) {
|
||||
},
|
||||
{
|
||||
status: 500,
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+34
-15
@@ -1,5 +1,8 @@
|
||||
import "./globals.css";
|
||||
import { NavbarRight } from "@/components/NavbarRight";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { ClerkProvider, UserButton } from "@clerk/nextjs";
|
||||
import { Github } from "lucide-react";
|
||||
import type { Metadata } from "next";
|
||||
import { Inter } from "next/font/google";
|
||||
import { Toaster } from "sonner";
|
||||
@@ -18,21 +21,37 @@ export default function RootLayout({
|
||||
}) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<body className={inter.className}>
|
||||
<main className="flex min-h-screen flex-col items-center justify-start">
|
||||
<div className="w-full h-18 flex items-center gap-4 p-4 border-b border-gray-200">
|
||||
<a className="font-bold text-lg hover:underline" href="/">
|
||||
Comfy Deploy
|
||||
</a>
|
||||
<NavbarRight />
|
||||
{/* <div></div> */}
|
||||
</div>
|
||||
<div className="md:px-10 px-6 w-full flex items-start">
|
||||
{children}
|
||||
</div>
|
||||
<Toaster richColors />
|
||||
</main>
|
||||
</body>
|
||||
<ClerkProvider>
|
||||
<body className={inter.className}>
|
||||
<main className="flex min-h-screen flex-col items-center justify-start">
|
||||
<div className="w-full h-18 flex items-center justify-between gap-4 p-4 border-b border-gray-200">
|
||||
<div className="flex flex-row items-center gap-4">
|
||||
<a className="font-bold text-lg hover:underline" href="/">
|
||||
ComfyUI Deploy
|
||||
</a>
|
||||
<NavbarRight />
|
||||
</div>
|
||||
<div className="flex flex-row items-center gap-2">
|
||||
<UserButton />
|
||||
<Button
|
||||
asChild
|
||||
variant={"outline"}
|
||||
className="rounded-full aspect-square p-2"
|
||||
>
|
||||
<a target="_blank" href="https://github.com/BennyKok/comfyui-deploy">
|
||||
<Github />
|
||||
</a>
|
||||
</Button>
|
||||
</div>
|
||||
{/* <div></div> */}
|
||||
</div>
|
||||
<div className="md:px-10 px-6 w-full flex items-start">
|
||||
{children}
|
||||
</div>
|
||||
<Toaster richColors />
|
||||
</main>
|
||||
</body>
|
||||
</ClerkProvider>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user