@@ -117,9 +109,7 @@
-
+
-
+
@@ -236,6 +223,7 @@ import { deployGatewayName, type GridGateway, loadDeploymentGateways } from "../
import { getGrid } from "../utils/grid";
import { normalizeError } from "../utils/helpers";
import { generateName } from "../utils/strings";
+import { isAvailableName } from "../utils/validators";
import IconActionBtn from "./icon_action_btn.vue";
import ListTable from "./list_table.vue";
import { useLayout } from "./weblet_layout.vue";
@@ -268,7 +256,7 @@ export default {
(props.vm.projectName.toLowerCase().includes(ProjectName.Fullvm.toLowerCase()) ? "fvm" : "vm") +
grid!.config.twinId;
prefix.value = oldPrefix.value + props.vm.name;
- subdomain.value = generateName({}, 35 - prefix.value.length > 7 ? 7 : 35 - prefix.value.length);
+ subdomain.value = generateName({ prefix: prefix.value }, 4);
await loadGateways();
});
@@ -313,7 +301,7 @@ export default {
}
await deployGatewayName(grid, selectionDetails.value!.domain, {
- subdomain: prefix.value + subdomain.value,
+ subdomain: subdomain.value,
ip,
port: port.value,
network: networkName,
@@ -346,6 +334,11 @@ export default {
}
}
+ async function validateSubdomain() {
+ const grid = await getGrid(profileManager.profile!, props.vm.projectName);
+ return await isAvailableName(grid!, subdomain.value);
+ }
+
return {
profileManager,
@@ -375,6 +368,7 @@ export default {
gatewaysToDelete,
deleting,
deleteSelectedGateways,
+ validateSubdomain,
};
},
};
diff --git a/packages/playground/src/utils/validators.ts b/packages/playground/src/utils/validators.ts
index 340a933749..d76d85130b 100644
--- a/packages/playground/src/utils/validators.ts
+++ b/packages/playground/src/utils/validators.ts
@@ -1,3 +1,4 @@
+import type { GridClient } from "@threefold/grid_client";
import StellarSdk from "stellar-sdk";
import validator from "validator";
import type { Options } from "validator/lib/isBoolean";
@@ -761,3 +762,10 @@ export async function isValidStellarAddress(target: string): Promise
return { message };
}
}
+
+export async function isAvailableName(grid: GridClient, name: string) {
+ const valid = await grid.contracts.get_name_contract({ name });
+ if (name && !!valid) {
+ return { message: "Name is already taken." };
+ }
+}