mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-25 05:08:46 +00:00
refactor: remove unused server value and update network handling logic
- Eliminated the unused DOKPLOY_SERVER_VALUE constant from the network handling component. - Updated the default serverId to undefined in the network form values and adjusted related logic to ensure compatibility with cloud environments. - Enhanced server validation in the createNetwork function to require a serverId when in cloud mode, improving error handling for network creation.
This commit is contained in:
@@ -48,9 +48,6 @@ const networkDriverEnum = [
|
|||||||
/** Sentinel for "no scope" */
|
/** Sentinel for "no scope" */
|
||||||
const SCOPE_EMPTY = "__scope_none__";
|
const SCOPE_EMPTY = "__scope_none__";
|
||||||
|
|
||||||
/** Value for "Dokploy server" (local / no specific server). Not used in cloud. */
|
|
||||||
const DOKPLOY_SERVER_VALUE = "__dokploy_server__";
|
|
||||||
|
|
||||||
const ipamConfigEntrySchema = z.object({
|
const ipamConfigEntrySchema = z.object({
|
||||||
subnet: z.string().optional(),
|
subnet: z.string().optional(),
|
||||||
ipRange: z.string().optional(),
|
ipRange: z.string().optional(),
|
||||||
@@ -78,7 +75,7 @@ const defaultValues: NetworkFormValues = {
|
|||||||
name: "",
|
name: "",
|
||||||
driver: "bridge",
|
driver: "bridge",
|
||||||
scope: SCOPE_EMPTY,
|
scope: SCOPE_EMPTY,
|
||||||
serverId: DOKPLOY_SERVER_VALUE,
|
serverId: undefined,
|
||||||
internal: false,
|
internal: false,
|
||||||
attachable: false,
|
attachable: false,
|
||||||
ingress: false,
|
ingress: false,
|
||||||
@@ -134,7 +131,7 @@ export const HandleNetwork = ({ networkId, children }: HandleNetworkProps) => {
|
|||||||
name: network.name,
|
name: network.name,
|
||||||
driver: network.driver,
|
driver: network.driver,
|
||||||
scope: network.scope ?? SCOPE_EMPTY,
|
scope: network.scope ?? SCOPE_EMPTY,
|
||||||
serverId: network.serverId ?? DOKPLOY_SERVER_VALUE,
|
serverId: network.serverId || undefined,
|
||||||
internal: network.internal,
|
internal: network.internal,
|
||||||
attachable: network.attachable,
|
attachable: network.attachable,
|
||||||
enableIPv4: network.enableIPv4,
|
enableIPv4: network.enableIPv4,
|
||||||
@@ -157,7 +154,7 @@ export const HandleNetwork = ({ networkId, children }: HandleNetworkProps) => {
|
|||||||
name: data.name,
|
name: data.name,
|
||||||
driver: data.driver,
|
driver: data.driver,
|
||||||
scope,
|
scope,
|
||||||
serverId: data.serverId ?? undefined,
|
serverId: data.serverId || undefined,
|
||||||
internal: data.internal,
|
internal: data.internal,
|
||||||
attachable: data.attachable,
|
attachable: data.attachable,
|
||||||
ingress: data.ingress,
|
ingress: data.ingress,
|
||||||
@@ -268,7 +265,7 @@ export const HandleNetwork = ({ networkId, children }: HandleNetworkProps) => {
|
|||||||
<FormLabel>Server</FormLabel>
|
<FormLabel>Server</FormLabel>
|
||||||
<Select
|
<Select
|
||||||
onValueChange={field.onChange}
|
onValueChange={field.onChange}
|
||||||
value={field.value ?? DOKPLOY_SERVER_VALUE}
|
value={field.value ?? undefined}
|
||||||
>
|
>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<SelectTrigger>
|
<SelectTrigger>
|
||||||
@@ -277,7 +274,7 @@ export const HandleNetwork = ({ networkId, children }: HandleNetworkProps) => {
|
|||||||
</FormControl>
|
</FormControl>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
{!isCloud && (
|
{!isCloud && (
|
||||||
<SelectItem value={DOKPLOY_SERVER_VALUE}>
|
<SelectItem value={undefined}>
|
||||||
Dokploy server
|
Dokploy server
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
} from "@dokploy/server/db/schema";
|
} from "@dokploy/server/db/schema";
|
||||||
import { TRPCError } from "@trpc/server";
|
import { TRPCError } from "@trpc/server";
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
|
import { IS_CLOUD } from "../constants";
|
||||||
import { getRemoteDocker } from "../utils/servers/remote-docker";
|
import { getRemoteDocker } from "../utils/servers/remote-docker";
|
||||||
|
|
||||||
export const findNetworkById = async (networkId: string) => {
|
export const findNetworkById = async (networkId: string) => {
|
||||||
@@ -29,6 +30,13 @@ export const createNetwork = async (
|
|||||||
input: typeof apiCreateNetwork._type,
|
input: typeof apiCreateNetwork._type,
|
||||||
organizationId: string,
|
organizationId: string,
|
||||||
) => {
|
) => {
|
||||||
|
if (IS_CLOUD)
|
||||||
|
if (!input.serverId) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "BAD_REQUEST",
|
||||||
|
message: "Server is required",
|
||||||
|
});
|
||||||
|
}
|
||||||
const created = await db.transaction(async (tx) => {
|
const created = await db.transaction(async (tx) => {
|
||||||
const [row] = await tx
|
const [row] = await tx
|
||||||
.insert(network)
|
.insert(network)
|
||||||
@@ -64,13 +72,10 @@ export const createNetwork = async (
|
|||||||
Attachable: row.attachable,
|
Attachable: row.attachable,
|
||||||
Ingress: row.ingress,
|
Ingress: row.ingress,
|
||||||
EnableIPv6: row.enableIPv6,
|
EnableIPv6: row.enableIPv6,
|
||||||
IPAM:
|
IPAM: {
|
||||||
ipamConfig.length > 0 || ipam.driver
|
Driver: ipam.driver ?? "default",
|
||||||
? {
|
Config: ipamConfig.length > 0 ? ipamConfig : undefined,
|
||||||
Driver: ipam.driver ?? "default",
|
},
|
||||||
Config: ipamConfig.length > 0 ? ipamConfig : undefined,
|
|
||||||
}
|
|
||||||
: undefined,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return row;
|
return row;
|
||||||
|
|||||||
Reference in New Issue
Block a user