mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-10-20 15:35:23 +00:00
refactor(cloud): add deploy to external API
This commit is contained in:
@@ -48,6 +48,7 @@ import {
|
||||
addNewService,
|
||||
checkServiceAccess,
|
||||
IS_CLOUD,
|
||||
findProjectById,
|
||||
// uploadFileSchema
|
||||
} from "@dokploy/builders";
|
||||
import { uploadFileSchema } from "@/utils/schema";
|
||||
@@ -65,6 +66,14 @@ export const applicationRouter = createTRPCRouter({
|
||||
if (ctx.user.rol === "user") {
|
||||
await checkServiceAccess(ctx.user.authId, input.projectId, "create");
|
||||
}
|
||||
|
||||
const project = await findProjectById(input.projectId);
|
||||
if (project.adminId !== ctx.user.adminId) {
|
||||
throw new TRPCError({
|
||||
code: "UNAUTHORIZED",
|
||||
message: "You are not authorized to access this project",
|
||||
});
|
||||
}
|
||||
const newApplication = await createApplication(input);
|
||||
|
||||
if (ctx.user.rol === "user") {
|
||||
@@ -545,7 +554,6 @@ export const applicationRouter = createTRPCRouter({
|
||||
});
|
||||
|
||||
await unzipDrop(zipFile, app);
|
||||
|
||||
const jobData: DeploymentJob = {
|
||||
applicationId: app.applicationId,
|
||||
titleLog: "Manual deployment",
|
||||
@@ -554,6 +562,12 @@ export const applicationRouter = createTRPCRouter({
|
||||
applicationType: "application",
|
||||
server: !!app.serverId,
|
||||
};
|
||||
if (IS_CLOUD && app.serverId) {
|
||||
jobData.serverId = app.serverId;
|
||||
await deploy(jobData);
|
||||
return true;
|
||||
}
|
||||
|
||||
await myQueue.add(
|
||||
"deployments",
|
||||
{ ...jobData },
|
||||
|
||||
@@ -64,6 +64,13 @@ export const composeRouter = createTRPCRouter({
|
||||
if (ctx.user.rol === "user") {
|
||||
await checkServiceAccess(ctx.user.authId, input.projectId, "create");
|
||||
}
|
||||
const project = await findProjectById(input.projectId);
|
||||
if (project.adminId !== ctx.user.adminId) {
|
||||
throw new TRPCError({
|
||||
code: "UNAUTHORIZED",
|
||||
message: "You are not authorized to access this project",
|
||||
});
|
||||
}
|
||||
const newService = await createCompose(input);
|
||||
|
||||
if (ctx.user.rol === "user") {
|
||||
@@ -278,7 +285,6 @@ export const composeRouter = createTRPCRouter({
|
||||
};
|
||||
if (IS_CLOUD && compose.serverId) {
|
||||
jobData.serverId = compose.serverId;
|
||||
|
||||
await deploy(jobData);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
addNewService,
|
||||
checkServiceAccess,
|
||||
createMount,
|
||||
findProjectById,
|
||||
} from "@dokploy/builders";
|
||||
|
||||
export const mariadbRouter = createTRPCRouter({
|
||||
@@ -35,6 +36,13 @@ export const mariadbRouter = createTRPCRouter({
|
||||
await checkServiceAccess(ctx.user.authId, input.projectId, "create");
|
||||
}
|
||||
|
||||
const project = await findProjectById(input.projectId);
|
||||
if (project.adminId !== ctx.user.adminId) {
|
||||
throw new TRPCError({
|
||||
code: "UNAUTHORIZED",
|
||||
message: "You are not authorized to access this project",
|
||||
});
|
||||
}
|
||||
const newMariadb = await createMariadb(input);
|
||||
if (ctx.user.rol === "user") {
|
||||
await addNewService(ctx.user.authId, newMariadb.mariadbId);
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
startServiceRemote,
|
||||
stopService,
|
||||
stopServiceRemote,
|
||||
findProjectById,
|
||||
} from "@dokploy/builders";
|
||||
|
||||
export const mongoRouter = createTRPCRouter({
|
||||
@@ -35,6 +36,13 @@ export const mongoRouter = createTRPCRouter({
|
||||
await checkServiceAccess(ctx.user.authId, input.projectId, "create");
|
||||
}
|
||||
|
||||
const project = await findProjectById(input.projectId);
|
||||
if (project.adminId !== ctx.user.adminId) {
|
||||
throw new TRPCError({
|
||||
code: "UNAUTHORIZED",
|
||||
message: "You are not authorized to access this project",
|
||||
});
|
||||
}
|
||||
const newMongo = await createMongo(input);
|
||||
if (ctx.user.rol === "user") {
|
||||
await addNewService(ctx.user.authId, newMongo.mongoId);
|
||||
|
||||
@@ -26,6 +26,7 @@ import {
|
||||
startServiceRemote,
|
||||
stopService,
|
||||
stopServiceRemote,
|
||||
findProjectById,
|
||||
} from "@dokploy/builders";
|
||||
|
||||
export const mysqlRouter = createTRPCRouter({
|
||||
@@ -36,6 +37,13 @@ export const mysqlRouter = createTRPCRouter({
|
||||
if (ctx.user.rol === "user") {
|
||||
await checkServiceAccess(ctx.user.authId, input.projectId, "create");
|
||||
}
|
||||
const project = await findProjectById(input.projectId);
|
||||
if (project.adminId !== ctx.user.adminId) {
|
||||
throw new TRPCError({
|
||||
code: "UNAUTHORIZED",
|
||||
message: "You are not authorized to access this project",
|
||||
});
|
||||
}
|
||||
|
||||
const newMysql = await createMysql(input);
|
||||
if (ctx.user.rol === "user") {
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
findPostgresById,
|
||||
removePostgresById,
|
||||
updatePostgresById,
|
||||
findProjectById,
|
||||
} from "@dokploy/builders";
|
||||
|
||||
export const postgresRouter = createTRPCRouter({
|
||||
@@ -35,6 +36,13 @@ export const postgresRouter = createTRPCRouter({
|
||||
await checkServiceAccess(ctx.user.authId, input.projectId, "create");
|
||||
}
|
||||
|
||||
const project = await findProjectById(input.projectId);
|
||||
if (project.adminId !== ctx.user.adminId) {
|
||||
throw new TRPCError({
|
||||
code: "UNAUTHORIZED",
|
||||
message: "You are not authorized to access this project",
|
||||
});
|
||||
}
|
||||
const newPostgres = await createPostgres(input);
|
||||
if (ctx.user.rol === "user") {
|
||||
await addNewService(ctx.user.authId, newPostgres.postgresId);
|
||||
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
removeRedisById,
|
||||
updateRedisById,
|
||||
IS_CLOUD,
|
||||
findProjectById,
|
||||
} from "@dokploy/builders";
|
||||
|
||||
export const redisRouter = createTRPCRouter({
|
||||
@@ -38,6 +39,13 @@ export const redisRouter = createTRPCRouter({
|
||||
await checkServiceAccess(ctx.user.authId, input.projectId, "create");
|
||||
}
|
||||
|
||||
const project = await findProjectById(input.projectId);
|
||||
if (project.adminId !== ctx.user.adminId) {
|
||||
throw new TRPCError({
|
||||
code: "UNAUTHORIZED",
|
||||
message: "You are not authorized to access this project",
|
||||
});
|
||||
}
|
||||
const newRedis = await createRedis(input);
|
||||
if (ctx.user.rol === "user") {
|
||||
await addNewService(ctx.user.authId, newRedis.redisId);
|
||||
|
||||
Reference in New Issue
Block a user