mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-19 08:48:34 +02:00
save
This commit is contained in:
parent
a35e24bc0e
commit
62238948e0
2 changed files with 37 additions and 10 deletions
|
@ -1,12 +1,26 @@
|
||||||
import { InferSelectModel } from "drizzle-orm";
|
import { InferSelectModel } from "drizzle-orm";
|
||||||
import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core";
|
import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core";
|
||||||
|
|
||||||
|
export const domains = sqliteTable("domains", {
|
||||||
|
domainId: integer("domainId").primaryKey({ autoIncrement: true }),
|
||||||
|
baseDomain: text("domain").notNull().unique()
|
||||||
|
});
|
||||||
|
|
||||||
export const orgs = sqliteTable("orgs", {
|
export const orgs = sqliteTable("orgs", {
|
||||||
orgId: text("orgId").primaryKey(),
|
orgId: text("orgId").primaryKey(),
|
||||||
name: text("name").notNull(),
|
name: text("name").notNull(),
|
||||||
domain: text("domain").notNull()
|
domain: text("domain").notNull()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const orgDomains = sqliteTable("orgDomains", {
|
||||||
|
orgId: text("orgId")
|
||||||
|
.notNull()
|
||||||
|
.references(() => orgs.orgId, { onDelete: "cascade" }),
|
||||||
|
domainId: integer("domainId")
|
||||||
|
.notNull()
|
||||||
|
.references(() => domains.domainId, { onDelete: "cascade" })
|
||||||
|
});
|
||||||
|
|
||||||
export const sites = sqliteTable("sites", {
|
export const sites = sqliteTable("sites", {
|
||||||
siteId: integer("siteId").primaryKey({ autoIncrement: true }),
|
siteId: integer("siteId").primaryKey({ autoIncrement: true }),
|
||||||
orgId: text("orgId")
|
orgId: text("orgId")
|
||||||
|
@ -43,6 +57,9 @@ export const resources = sqliteTable("resources", {
|
||||||
name: text("name").notNull(),
|
name: text("name").notNull(),
|
||||||
subdomain: text("subdomain"),
|
subdomain: text("subdomain"),
|
||||||
fullDomain: text("fullDomain"),
|
fullDomain: text("fullDomain"),
|
||||||
|
domainId: integer("domainId").references(() => domains.domainId, {
|
||||||
|
onDelete: "set null"
|
||||||
|
}),
|
||||||
ssl: integer("ssl", { mode: "boolean" }).notNull().default(false),
|
ssl: integer("ssl", { mode: "boolean" }).notNull().default(false),
|
||||||
blockAccess: integer("blockAccess", { mode: "boolean" })
|
blockAccess: integer("blockAccess", { mode: "boolean" })
|
||||||
.notNull()
|
.notNull()
|
||||||
|
@ -55,7 +72,9 @@ export const resources = sqliteTable("resources", {
|
||||||
.notNull()
|
.notNull()
|
||||||
.default(false),
|
.default(false),
|
||||||
isBaseDomain: integer("isBaseDomain", { mode: "boolean" }),
|
isBaseDomain: integer("isBaseDomain", { mode: "boolean" }),
|
||||||
applyRules: integer("applyRules", { mode: "boolean" }).notNull().default(false)
|
applyRules: integer("applyRules", { mode: "boolean" })
|
||||||
|
.notNull()
|
||||||
|
.default(false)
|
||||||
});
|
});
|
||||||
|
|
||||||
export const targets = sqliteTable("targets", {
|
export const targets = sqliteTable("targets", {
|
||||||
|
|
|
@ -34,15 +34,27 @@ const configSchema = z.object({
|
||||||
.transform(getEnvOrYaml("APP_DASHBOARDURL"))
|
.transform(getEnvOrYaml("APP_DASHBOARDURL"))
|
||||||
.pipe(z.string().url())
|
.pipe(z.string().url())
|
||||||
.transform((url) => url.toLowerCase()),
|
.transform((url) => url.toLowerCase()),
|
||||||
base_domain: hostnameSchema
|
|
||||||
.optional()
|
|
||||||
.transform(getEnvOrYaml("APP_BASEDOMAIN"))
|
|
||||||
.pipe(hostnameSchema)
|
|
||||||
.transform((url) => url.toLowerCase()),
|
|
||||||
log_level: z.enum(["debug", "info", "warn", "error"]),
|
log_level: z.enum(["debug", "info", "warn", "error"]),
|
||||||
save_logs: z.boolean(),
|
save_logs: z.boolean(),
|
||||||
log_failed_attempts: z.boolean().optional()
|
log_failed_attempts: z.boolean().optional()
|
||||||
}),
|
}),
|
||||||
|
domains: z
|
||||||
|
.array(
|
||||||
|
z.object({
|
||||||
|
base_domain: hostnameSchema.transform((url) =>
|
||||||
|
url.toLowerCase()
|
||||||
|
)
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.refine(
|
||||||
|
(data) => {
|
||||||
|
const baseDomains = data.map((d) => d.base_domain);
|
||||||
|
return new Set(baseDomains).size === baseDomains.length;
|
||||||
|
},
|
||||||
|
{
|
||||||
|
message: "Base domains must be unique"
|
||||||
|
}
|
||||||
|
),
|
||||||
server: z.object({
|
server: z.object({
|
||||||
external_port: portSchema
|
external_port: portSchema
|
||||||
.optional()
|
.optional()
|
||||||
|
@ -283,10 +295,6 @@ export class Config {
|
||||||
return this.rawConfig;
|
return this.rawConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getBaseDomain(): string {
|
|
||||||
return this.rawConfig.app.base_domain;
|
|
||||||
}
|
|
||||||
|
|
||||||
public getNoReplyEmail(): string | undefined {
|
public getNoReplyEmail(): string | undefined {
|
||||||
return (
|
return (
|
||||||
this.rawConfig.email?.no_reply || this.rawConfig.email?.smtp_user
|
this.rawConfig.email?.no_reply || this.rawConfig.email?.smtp_user
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue