Skip to content

Commit

Permalink
block and unikernel name checks
Browse files Browse the repository at this point in the history
  • Loading branch information
PizieDust committed Nov 8, 2024
1 parent 6b20fc4 commit de852fd
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions assets/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ async function deployUnikernel() {
const binary = document.getElementById("unikernel-binary").files[0];
const molly_csrf = document.getElementById("molly-csrf").value;
const formAlert = document.getElementById("form-alert");
if (!name || !binary) {
if (!isValidName(name) || !binary) {
formAlert.classList.remove("hidden", "text-primary-500");
formAlert.classList.add("text-secondary-500");
formAlert.textContent = "Please fill in the required data"
Expand Down Expand Up @@ -579,7 +579,7 @@ async function createVolume() {
const block_compressed = document.getElementById("block_compressed").checked;
const block_data = document.getElementById("block_data").files[0];
try {
if (block_name === "") {
if (!isValidName(block_name)) {
formAlert.classList.remove("hidden", "text-primary-500");
formAlert.classList.add("text-secondary-500");
formAlert.textContent = "Please enter a name for this volume"
Expand Down Expand Up @@ -614,9 +614,9 @@ async function createVolume() {
if (data.status === 200) {
formAlert.classList.remove("hidden", "text-secondary-500");
formAlert.classList.add("text-primary-500");
formAlert.textContent = "Succesfully deleted";
formAlert.textContent = "Succesfully created";
postAlert("bg-primary-300", "Volume created succesfully");
setTimeout(() => window.location.reload(), 000);
setTimeout(() => window.location.reload(), 1000);
buttonLoading(createButton, false, "Create volume")
} else {
formAlert.classList.remove("hidden", "text-primary-500");
Expand All @@ -632,3 +632,17 @@ async function createVolume() {
buttonLoading(createButton, false, "Create volume")
}
}

function isValidName(s) {
const length = s.length;
if (length === 0 || length >= 64) return false;
if (s[0] === '-') return false;
for (let i = 0; i < length; i++) {
const char = s[i];
if (!(/[a-zA-Z0-9.-]/).test(char)) {
return false;
}
}
return true;
}

0 comments on commit de852fd

Please sign in to comment.