fix: fixed/improved handling of app names in api

This commit is contained in:
Aaron Gonzales
2024-12-16 18:13:07 +08:00
parent 829aa2a63c
commit 8e5b0988cf
10 changed files with 105 additions and 96 deletions

View File

@@ -1,3 +1,4 @@
import { generatePassword } from "@dokploy/server/templates/utils";
import { faker } from "@faker-js/faker";
import { customAlphabet } from "nanoid";
@@ -13,3 +14,17 @@ export const generateAppName = (type: string) => {
const nanoidPart = customNanoid();
return `${type}-${randomFakerElement}-${nanoidPart}`;
};
export const cleanAppName = (appName?: string) => {
if (!appName) {
return appName;
}
return appName.trim().replace(/ /g, "-");
};
export const buildAppName = (type: string, baseAppName?: string) => {
if (baseAppName) {
return `${cleanAppName(baseAppName)}-${generatePassword(6)}`;
}
return generateAppName(type);
};