merge0
This commit is contained in:
@@ -3,7 +3,7 @@ import { z } from "zod";
|
||||
export const APIKeyBodyRequest = z.object({
|
||||
user_id: z.string().optional().nullable(),
|
||||
org_id: z.string().optional().nullable(),
|
||||
iat: z.number(),
|
||||
iat: z.number().optional(),
|
||||
exp: z.number().optional(),
|
||||
});
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ export const insertCustomMachineSchema = createInsertSchema(machinesTable, {
|
||||
gpu: (schema) => schema.gpu.default("T4"),
|
||||
snapshot: (schema) =>
|
||||
schema.snapshot.default({
|
||||
comfyui: "8e3ee6468f4c2801c4736c139fd5632c25fbcab7",
|
||||
comfyui: "d0165d819afe76bd4e6bdd710eb5f3e571b6a804",
|
||||
git_custom_nodes: {
|
||||
"https://github.com/BennyKok/comfyui-deploy.git": {
|
||||
hash: "43fe0a384aa5fa9e141d4a264b2ed40a73b817bc",
|
||||
|
||||
@@ -66,7 +66,12 @@ export const createRun = withServerPromise(
|
||||
throw new Error("Workflow version not found");
|
||||
}
|
||||
|
||||
if (apiUser)
|
||||
let { userId, orgId } = auth();
|
||||
|
||||
// If is API user, check if they have access to the workflow
|
||||
if (apiUser) {
|
||||
userId = apiUser.user_id ?? null;
|
||||
orgId = apiUser.org_id;
|
||||
if (apiUser.org_id) {
|
||||
// is org api call, check org only
|
||||
if (apiUser.org_id != workflow_version_data.workflow.org_id) {
|
||||
@@ -81,6 +86,7 @@ export const createRun = withServerPromise(
|
||||
throw new Error("Workflow not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const workflow_api = workflow_version_data.workflow_api;
|
||||
|
||||
@@ -114,6 +120,10 @@ export const createRun = withServerPromise(
|
||||
workflow_inputs: inputs,
|
||||
machine_id: machine.id,
|
||||
origin: runOrigin,
|
||||
org_id: orgId,
|
||||
user_id: userId,
|
||||
gpu: machine.gpu,
|
||||
machine_type: machine.type,
|
||||
})
|
||||
.returning();
|
||||
|
||||
|
||||
@@ -6,16 +6,13 @@ import jwt from "jsonwebtoken";
|
||||
import { getOrgOrUserDisplayName } from "@/server/getOrgOrUserDisplayName";
|
||||
import { withServerPromise } from "@/server/withServerPromise";
|
||||
import "server-only";
|
||||
import { headers } from "next/headers";
|
||||
import { getUrlServerSide } from "./getUrlServerSide";
|
||||
|
||||
export const editWorkflowOnMachine = withServerPromise(
|
||||
async (workflow_version_id: string, machine_id: string) => {
|
||||
const { userId, orgId } = auth();
|
||||
|
||||
const headersList = headers();
|
||||
const host = headersList.get("host") || "";
|
||||
const protocol = headersList.get("x-forwarded-proto") || "";
|
||||
const domain = `${protocol}://${host}`;
|
||||
const domain = getUrlServerSide();
|
||||
|
||||
if (!userId) {
|
||||
throw new Error("No user id");
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import { db } from "@/db/db";
|
||||
import { and, desc, eq, isNull } from "drizzle-orm";
|
||||
import { subscriptionStatusTable } from "@/db/schema";
|
||||
import { APIKeyUserType } from "@/server/APIKeyBodyRequest";
|
||||
import { auth } from "@clerk/nextjs";
|
||||
|
||||
export async function getCurrentPlanWithAuth() {
|
||||
const { userId, orgId } = auth();
|
||||
|
||||
const sub = await getCurrentPlan({
|
||||
org_id: orgId,
|
||||
user_id: userId,
|
||||
});
|
||||
|
||||
return sub;
|
||||
}
|
||||
|
||||
export async function getCurrentPlan({ user_id, org_id }: APIKeyUserType) {
|
||||
if (!user_id) throw new Error("No user id");
|
||||
|
||||
const sub = await db.query.subscriptionStatusTable.findFirst({
|
||||
where: and(
|
||||
eq(subscriptionStatusTable.user_id, user_id),
|
||||
org_id
|
||||
? eq(subscriptionStatusTable.org_id, org_id)
|
||||
: isNull(subscriptionStatusTable.org_id),
|
||||
),
|
||||
orderBy: desc(subscriptionStatusTable.created_at),
|
||||
});
|
||||
|
||||
return sub;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { headers } from "next/headers";
|
||||
|
||||
export function getUrlServerSide() {
|
||||
const headersList = headers();
|
||||
const host = headersList.get("host") || "";
|
||||
const protocol = headersList.get("x-forwarded-proto") || "";
|
||||
const domain = `${protocol}://${host}`;
|
||||
|
||||
return domain;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
import Stripe from "stripe";
|
||||
|
||||
export const stripe = new Stripe(process.env.STRIPE_API_KEY!);
|
||||
Reference in New Issue
Block a user