mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor: add validations in domains
This commit is contained in:
@@ -12,6 +12,7 @@ import {
|
|||||||
import { api } from "@/utils/api";
|
import { api } from "@/utils/api";
|
||||||
import { Puzzle } from "lucide-react";
|
import { Puzzle } from "lucide-react";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
composeId: string;
|
composeId: string;
|
||||||
@@ -21,10 +22,17 @@ export const ShowConvertedCompose = ({ composeId }: Props) => {
|
|||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
const {
|
const {
|
||||||
data: compose,
|
data: compose,
|
||||||
isLoading,
|
|
||||||
error,
|
error,
|
||||||
isError,
|
isError,
|
||||||
} = api.compose.getConvertedCompose.useQuery({ composeId });
|
refetch,
|
||||||
|
} = api.compose.getConvertedCompose.useQuery(
|
||||||
|
{ composeId },
|
||||||
|
{
|
||||||
|
retry: false,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const { mutateAsync, isLoading } = api.compose.fetchSourceType.useMutation();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={isOpen} onOpenChange={setIsOpen}>
|
<Dialog open={isOpen} onOpenChange={setIsOpen}>
|
||||||
@@ -43,6 +51,23 @@ export const ShowConvertedCompose = ({ composeId }: Props) => {
|
|||||||
</DialogDescription>
|
</DialogDescription>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
{isError && <AlertBlock type="error">{error?.message}</AlertBlock>}
|
{isError && <AlertBlock type="error">{error?.message}</AlertBlock>}
|
||||||
|
<Button
|
||||||
|
isLoading={isLoading}
|
||||||
|
onClick={() => {
|
||||||
|
mutateAsync({ composeId })
|
||||||
|
.then(() => {
|
||||||
|
refetch();
|
||||||
|
toast.success("Fetched source type");
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
toast.error("Error to fetch source type", {
|
||||||
|
description: err.message,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Fetch
|
||||||
|
</Button>
|
||||||
<pre>
|
<pre>
|
||||||
<CodeEditor value={compose} language="yaml" readOnly height="50rem" />
|
<CodeEditor value={compose} language="yaml" readOnly height="50rem" />
|
||||||
</pre>
|
</pre>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import {
|
|||||||
import { myQueue } from "@/server/queues/queueSetup";
|
import { myQueue } from "@/server/queues/queueSetup";
|
||||||
import { createCommand } from "@/server/utils/builders/compose";
|
import { createCommand } from "@/server/utils/builders/compose";
|
||||||
import { randomizeComposeFile } from "@/server/utils/docker/compose";
|
import { randomizeComposeFile } from "@/server/utils/docker/compose";
|
||||||
import { addDomainToCompose } from "@/server/utils/docker/domain";
|
import { addDomainToCompose, cloneCompose } from "@/server/utils/docker/domain";
|
||||||
import { removeComposeDirectory } from "@/server/utils/filesystem/directory";
|
import { removeComposeDirectory } from "@/server/utils/filesystem/directory";
|
||||||
import { templates } from "@/templates/templates";
|
import { templates } from "@/templates/templates";
|
||||||
import type { TemplatesKeys } from "@/templates/types/templates-data.type";
|
import type { TemplatesKeys } from "@/templates/types/templates-data.type";
|
||||||
@@ -122,6 +122,21 @@ export const composeRouter = createTRPCRouter({
|
|||||||
.query(async ({ input }) => {
|
.query(async ({ input }) => {
|
||||||
return await loadServices(input.composeId, input.type);
|
return await loadServices(input.composeId, input.type);
|
||||||
}),
|
}),
|
||||||
|
fetchSourceType: protectedProcedure
|
||||||
|
.input(apiFindCompose)
|
||||||
|
.mutation(async ({ input }) => {
|
||||||
|
try {
|
||||||
|
const compose = await findComposeById(input.composeId);
|
||||||
|
await cloneCompose(compose);
|
||||||
|
return compose.sourceType;
|
||||||
|
} catch (err) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "BAD_REQUEST",
|
||||||
|
message: "Error to fetch source type",
|
||||||
|
cause: err,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
randomizeCompose: protectedProcedure
|
randomizeCompose: protectedProcedure
|
||||||
.input(apiRandomizeCompose)
|
.input(apiRandomizeCompose)
|
||||||
|
|||||||
@@ -71,9 +71,8 @@ export const addDomainToCompose = async (
|
|||||||
if (!serviceName) {
|
if (!serviceName) {
|
||||||
throw new Error("Service name not found");
|
throw new Error("Service name not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!result?.services?.[serviceName]) {
|
if (!result?.services?.[serviceName]) {
|
||||||
throw new Error("Service not found");
|
throw new Error(`The service ${serviceName} not found in the compose`);
|
||||||
}
|
}
|
||||||
if (!result.services[serviceName].labels) {
|
if (!result.services[serviceName].labels) {
|
||||||
result.services[serviceName].labels = [];
|
result.services[serviceName].labels = [];
|
||||||
|
|||||||
Reference in New Issue
Block a user