mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
feat(drag-n-drop): add support for drag n drop projects via zip #131
This commit is contained in:
57
server/utils/builders/drop.ts
Normal file
57
server/utils/builders/drop.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import fs from "node:fs/promises";
|
||||
import path, { join } from "node:path";
|
||||
import { APPLICATIONS_PATH } from "@/server/constants";
|
||||
import AdmZip from "adm-zip";
|
||||
import { recreateDirectory } from "../filesystem/directory";
|
||||
|
||||
export const unzipDrop = async (zipFile: File, appName: string) => {
|
||||
try {
|
||||
const basePath = APPLICATIONS_PATH;
|
||||
const outputPath = join(basePath, appName);
|
||||
await recreateDirectory(outputPath);
|
||||
const arrayBuffer = await zipFile.arrayBuffer();
|
||||
const buffer = Buffer.from(arrayBuffer);
|
||||
|
||||
const zip = new AdmZip(buffer);
|
||||
const zipEntries = zip.getEntries();
|
||||
|
||||
const rootEntries = zipEntries.filter(
|
||||
(entry) =>
|
||||
entry.entryName.split("/").length === 1 ||
|
||||
(entry.entryName.split("/").length === 2 &&
|
||||
entry.entryName.endsWith("/")),
|
||||
);
|
||||
|
||||
const hasSingleRootFolder = !!(
|
||||
rootEntries.length === 1 && rootEntries[0]?.isDirectory
|
||||
);
|
||||
const rootFolderName = hasSingleRootFolder
|
||||
? rootEntries[0]?.entryName.split("/")[0]
|
||||
: "";
|
||||
|
||||
for (const entry of zipEntries) {
|
||||
let filePath = entry.entryName;
|
||||
|
||||
if (
|
||||
hasSingleRootFolder &&
|
||||
rootFolderName &&
|
||||
filePath.startsWith(`${rootFolderName}/`)
|
||||
) {
|
||||
filePath = filePath.slice(rootFolderName?.length + 1);
|
||||
}
|
||||
|
||||
if (!filePath) continue;
|
||||
|
||||
const fullPath = path.join(outputPath, filePath);
|
||||
if (entry.isDirectory) {
|
||||
await fs.mkdir(fullPath, { recursive: true });
|
||||
} else {
|
||||
await fs.mkdir(path.dirname(fullPath), { recursive: true });
|
||||
await fs.writeFile(fullPath, entry.getData());
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error processing ZIP file:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -59,8 +59,15 @@ export const removeMonitoringDirectory = async (appName: string) => {
|
||||
export const getBuildAppDirectory = (application: Application) => {
|
||||
const { appName, buildType, sourceType, customGitBuildPath, dockerfile } =
|
||||
application;
|
||||
const buildPath =
|
||||
sourceType === "github" ? application?.buildPath : customGitBuildPath;
|
||||
let buildPath = "";
|
||||
|
||||
if (sourceType === "github") {
|
||||
buildPath = application?.buildPath || "";
|
||||
} else if (sourceType === "drop") {
|
||||
buildPath = application?.dropBuildPath || "";
|
||||
} else if (sourceType === "git") {
|
||||
buildPath = customGitBuildPath || "";
|
||||
}
|
||||
if (buildType === "dockerfile") {
|
||||
return path.join(
|
||||
APPLICATIONS_PATH,
|
||||
|
||||
Reference in New Issue
Block a user