feat: add new auth_request flow for logging in with comfy deploy

This commit is contained in:
BennyKok
2024-01-22 14:11:14 +08:00
parent 3043093d22
commit 47168930dc
25 changed files with 2424 additions and 272 deletions
+4 -4
View File
@@ -1,6 +1,6 @@
import * as schema from "./schema";
import { neonConfig, Pool } from "@neondatabase/serverless";
import { Pool, neonConfig } from "@neondatabase/serverless";
import { drizzle as neonDrizzle } from "drizzle-orm/neon-serverless";
import * as schema from "./schema";
const isDevContainer = process.env.REMOTE_CONTAINERS !== undefined;
@@ -9,7 +9,7 @@ if (process.env.VERCEL_ENV !== "production") {
// Set the WebSocket proxy to work with the local instance
if (isDevContainer) {
// Running inside a VS Code devcontainer
neonConfig.wsProxy = (host) => `host.docker.internal:5481/v1`;
neonConfig.wsProxy = (host) => "host.docker.internal:5481/v1";
} else {
// Not running inside a VS Code devcontainer
neonConfig.wsProxy = (host) => `${host}:5481/v1`;
@@ -26,5 +26,5 @@ export const db = neonDrizzle(
}),
{
schema,
}
},
);
+73 -63
View File
@@ -1,13 +1,13 @@
import { type InferSelectModel, relations } from "drizzle-orm";
import {
boolean,
integer,
jsonb,
pgEnum,
pgSchema,
text,
timestamp,
uuid,
boolean,
integer,
jsonb,
pgEnum,
pgSchema,
text,
timestamp,
uuid,
} from "drizzle-orm/pg-core";
import { createInsertSchema } from "drizzle-zod";
import { z } from "zod";
@@ -87,7 +87,7 @@ export const workflowVersionRelations = relations(
fields: [workflowVersionTable.workflow_id],
references: [workflowTable.id],
}),
})
}),
);
export const workflowRunStatus = pgEnum("workflow_run_status", [
@@ -130,30 +130,30 @@ export const machinesStatus = pgEnum("machine_status", [
// We still want to keep the workflow run record.
export const workflowRunsTable = dbSchema.table("workflow_runs", {
id: uuid("id").primaryKey().defaultRandom().notNull(),
// when workflow version deleted, still want to keep this record
workflow_version_id: uuid("workflow_version_id").references(
() => workflowVersionTable.id,
{
onDelete: "set null",
},
),
workflow_inputs:
jsonb("workflow_inputs").$type<Record<string, string | number>>(),
workflow_id: uuid("workflow_id")
.notNull()
.references(() => workflowTable.id, {
onDelete: "cascade",
}),
// when machine deleted, still want to keep this record
machine_id: uuid("machine_id").references(() => machinesTable.id, {
onDelete: "set null",
}),
origin: workflowRunOrigin("origin").notNull().default("api"),
status: workflowRunStatus("status").notNull().default("not-started"),
ended_at: timestamp("ended_at"),
created_at: timestamp("created_at").defaultNow().notNull(),
started_at: timestamp("started_at"),
id: uuid("id").primaryKey().defaultRandom().notNull(),
// when workflow version deleted, still want to keep this record
workflow_version_id: uuid("workflow_version_id").references(
() => workflowVersionTable.id,
{
onDelete: "set null",
},
),
workflow_inputs:
jsonb("workflow_inputs").$type<Record<string, string | number>>(),
workflow_id: uuid("workflow_id")
.notNull()
.references(() => workflowTable.id, {
onDelete: "cascade",
}),
// when machine deleted, still want to keep this record
machine_id: uuid("machine_id").references(() => machinesTable.id, {
onDelete: "set null",
}),
origin: workflowRunOrigin("origin").notNull().default("api"),
status: workflowRunStatus("status").notNull().default("not-started"),
ended_at: timestamp("ended_at"),
created_at: timestamp("created_at").defaultNow().notNull(),
started_at: timestamp("started_at"),
});
export const workflowRunRelations = relations(
@@ -172,7 +172,7 @@ export const workflowRunRelations = relations(
fields: [workflowRunsTable.workflow_id],
references: [workflowTable.id],
}),
})
}),
);
// We still want to keep the workflow run record.
@@ -196,7 +196,7 @@ export const workflowOutputRelations = relations(
fields: [workflowRunOutputs.run_id],
references: [workflowRunsTable.id],
}),
})
}),
);
// when user delete, also delete all the workflow versions
@@ -229,7 +229,7 @@ export const snapshotType = z.object({
z.object({
hash: z.string(),
disabled: z.boolean(),
})
}),
),
file_custom_nodes: z.array(z.any()),
});
@@ -244,7 +244,7 @@ export const showcaseMedia = z.array(
z.object({
url: z.string(),
isCover: z.boolean().default(false),
})
}),
);
export const showcaseMediaNullable = z
@@ -252,36 +252,36 @@ export const showcaseMediaNullable = z
z.object({
url: z.string(),
isCover: z.boolean().default(false),
})
}),
)
.nullable();
export const deploymentsTable = dbSchema.table("deployments", {
id: uuid("id").primaryKey().defaultRandom().notNull(),
user_id: text("user_id")
.references(() => usersTable.id, {
onDelete: "cascade",
})
.notNull(),
org_id: text("org_id"),
workflow_version_id: uuid("workflow_version_id")
.notNull()
.references(() => workflowVersionTable.id),
workflow_id: uuid("workflow_id")
.notNull()
.references(() => workflowTable.id, {
onDelete: "cascade",
}),
machine_id: uuid("machine_id")
.notNull()
.references(() => machinesTable.id),
share_slug: text("share_slug").unique(),
description: text("description"),
showcase_media:
jsonb("showcase_media").$type<z.infer<typeof showcaseMedia>>(),
environment: deploymentEnvironment("environment").notNull(),
created_at: timestamp("created_at").defaultNow().notNull(),
updated_at: timestamp("updated_at").defaultNow().notNull(),
id: uuid("id").primaryKey().defaultRandom().notNull(),
user_id: text("user_id")
.references(() => usersTable.id, {
onDelete: "cascade",
})
.notNull(),
org_id: text("org_id"),
workflow_version_id: uuid("workflow_version_id")
.notNull()
.references(() => workflowVersionTable.id),
workflow_id: uuid("workflow_id")
.notNull()
.references(() => workflowTable.id, {
onDelete: "cascade",
}),
machine_id: uuid("machine_id")
.notNull()
.references(() => machinesTable.id),
share_slug: text("share_slug").unique(),
description: text("description"),
showcase_media:
jsonb("showcase_media").$type<z.infer<typeof showcaseMedia>>(),
environment: deploymentEnvironment("environment").notNull(),
created_at: timestamp("created_at").defaultNow().notNull(),
updated_at: timestamp("updated_at").defaultNow().notNull(),
});
export const publicShareDeployment = z.object({
@@ -331,6 +331,16 @@ export const apiKeyTable = dbSchema.table("api_keys", {
updated_at: timestamp("updated_at").defaultNow().notNull(),
});
export const authRequestsTable = dbSchema.table("auth_requests", {
request_id: text("request_id").primaryKey().notNull(),
user_id: text("user_id"),
org_id: text("org_id"),
api_hash: text("api_hash"),
created_at: timestamp("created_at").defaultNow().notNull(),
expired_date: timestamp("expired_date"),
updated_at: timestamp("updated_at").defaultNow().notNull(),
});
export type UserType = InferSelectModel<typeof usersTable>;
export type WorkflowType = InferSelectModel<typeof workflowTable>;
export type MachineType = InferSelectModel<typeof machinesTable>;