mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-07-24 23:35:24 +02:00
feat: add web UI file upload to Docker containers
This commit is contained in:
@@ -7,10 +7,12 @@ import {
|
||||
getContainersByAppNameMatch,
|
||||
getServiceContainersByAppName,
|
||||
getStackContainersByAppName,
|
||||
uploadFileToContainer,
|
||||
} from "@dokploy/server";
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { z } from "zod";
|
||||
import { createTRPCRouter, protectedProcedure } from "../trpc";
|
||||
import { createTRPCRouter, protectedProcedure, uploadProcedure } from "../trpc";
|
||||
import { uploadFileToContainerSchema } from "@/utils/schema";
|
||||
|
||||
export const containerIdRegex = /^[a-zA-Z0-9.\-_]+$/;
|
||||
|
||||
@@ -143,4 +145,38 @@ export const dockerRouter = createTRPCRouter({
|
||||
}
|
||||
return await getServiceContainersByAppName(input.appName, input.serverId);
|
||||
}),
|
||||
|
||||
uploadFileToContainer: protectedProcedure
|
||||
.use(uploadProcedure)
|
||||
.input(uploadFileToContainerSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
if (input.serverId) {
|
||||
const server = await findServerById(input.serverId);
|
||||
if (server.organizationId !== ctx.session?.activeOrganizationId) {
|
||||
throw new TRPCError({ code: "UNAUTHORIZED" });
|
||||
}
|
||||
}
|
||||
|
||||
const file = input.file;
|
||||
if (!(file instanceof File)) {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "Invalid file provided",
|
||||
});
|
||||
}
|
||||
|
||||
// Convert File to Buffer
|
||||
const arrayBuffer = await file.arrayBuffer();
|
||||
const fileBuffer = Buffer.from(arrayBuffer);
|
||||
|
||||
await uploadFileToContainer(
|
||||
input.containerId,
|
||||
fileBuffer,
|
||||
file.name,
|
||||
input.destinationPath,
|
||||
input.serverId || null,
|
||||
);
|
||||
|
||||
return { success: true, message: "File uploaded successfully" };
|
||||
}),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user