mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-13 15:35:17 +00:00
refactor(patch): enforce minimum length for ID input and streamline repo directory access
- Updated ID input validation to require a minimum length of 1 character. - Simplified the logic for accessing repository directories by consolidating return statements and removing unnecessary error handling for missing application or compose types.
This commit is contained in:
@@ -142,12 +142,14 @@ export const patchRouter = createTRPCRouter({
|
|||||||
readRepoDirectories: protectedProcedure
|
readRepoDirectories: protectedProcedure
|
||||||
.input(
|
.input(
|
||||||
z.object({
|
z.object({
|
||||||
id: z.string(),
|
id: z.string().min(1),
|
||||||
type: z.enum(["application", "compose"]),
|
type: z.enum(["application", "compose"]),
|
||||||
repoPath: z.string(),
|
repoPath: z.string(),
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
|
let serverId: string | null = null;
|
||||||
|
|
||||||
if (input.type === "application") {
|
if (input.type === "application") {
|
||||||
const app = await findApplicationById(input.id);
|
const app = await findApplicationById(input.id);
|
||||||
if (
|
if (
|
||||||
@@ -159,7 +161,7 @@ export const patchRouter = createTRPCRouter({
|
|||||||
message: "You are not authorized to access this application",
|
message: "You are not authorized to access this application",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return await readPatchRepoDirectory(input.repoPath, app.serverId);
|
serverId = app.serverId;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input.type === "compose") {
|
if (input.type === "compose") {
|
||||||
@@ -173,19 +175,16 @@ export const patchRouter = createTRPCRouter({
|
|||||||
message: "You are not authorized to access this compose",
|
message: "You are not authorized to access this compose",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return await readPatchRepoDirectory(input.repoPath, compose.serverId);
|
serverId = compose.serverId;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new TRPCError({
|
return await readPatchRepoDirectory(input.repoPath, serverId);
|
||||||
code: "BAD_REQUEST",
|
|
||||||
message: "Either application or compose must be provided",
|
|
||||||
});
|
|
||||||
}),
|
}),
|
||||||
|
|
||||||
readRepoFile: protectedProcedure
|
readRepoFile: protectedProcedure
|
||||||
.input(
|
.input(
|
||||||
z.object({
|
z.object({
|
||||||
id: z.string(),
|
id: z.string().min(1),
|
||||||
type: z.enum(["application", "compose"]),
|
type: z.enum(["application", "compose"]),
|
||||||
filePath: z.string(),
|
filePath: z.string(),
|
||||||
}),
|
}),
|
||||||
@@ -246,7 +245,7 @@ export const patchRouter = createTRPCRouter({
|
|||||||
saveFileAsPatch: protectedProcedure
|
saveFileAsPatch: protectedProcedure
|
||||||
.input(
|
.input(
|
||||||
z.object({
|
z.object({
|
||||||
id: z.string(),
|
id: z.string().min(1),
|
||||||
type: z.enum(["application", "compose"]),
|
type: z.enum(["application", "compose"]),
|
||||||
filePath: z.string(),
|
filePath: z.string(),
|
||||||
content: z.string(),
|
content: z.string(),
|
||||||
@@ -308,7 +307,7 @@ export const patchRouter = createTRPCRouter({
|
|||||||
markFileForDeletion: protectedProcedure
|
markFileForDeletion: protectedProcedure
|
||||||
.input(
|
.input(
|
||||||
z.object({
|
z.object({
|
||||||
id: z.string(),
|
id: z.string().min(1),
|
||||||
type: z.enum(["application", "compose"]),
|
type: z.enum(["application", "compose"]),
|
||||||
filePath: z.string(),
|
filePath: z.string(),
|
||||||
}),
|
}),
|
||||||
@@ -340,8 +339,6 @@ export const patchRouter = createTRPCRouter({
|
|||||||
|
|
||||||
return await markPatchForDeletion(input.filePath, input.id, input.type);
|
return await markPatchForDeletion(input.filePath, input.id, input.type);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// Cleanup
|
|
||||||
cleanPatchRepos: adminProcedure
|
cleanPatchRepos: adminProcedure
|
||||||
.input(z.object({ serverId: z.string().optional() }))
|
.input(z.object({ serverId: z.string().optional() }))
|
||||||
.mutation(async ({ input }) => {
|
.mutation(async ({ input }) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user