commit cda3d9e86509aeb7f6647e605da3f6de27f5dfdc
parent 77c7140bc76d98f5c1499346c7f2951e8af237f1
Author: René Wagner <apollo@rw-net.de>
Date: Sat, 25 Jan 2020 16:51:15 +0100
avoid readding an already existing url cause this deletes that stats
fix usage of "statusDiv" as errors where not shown anymore
Diffstat:
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/admin.php b/admin.php
@@ -35,6 +35,11 @@ if (isset($_GET["delete"]) || isset($_GET["add"])) {
echo "{\"status\": \"unvalid-url\"}";
exit;
}
+ if (array_key_exists($filtered["name"], $config_content["shortlinks"]))
+ {
+ echo "{\"status\": \"url-already-exists\"}";
+ exit;
+ }
$config_content["shortlinks"][$filtered["name"]] = $filtered["url"];
$stats_content[$filtered["name"]] = array();
}
diff --git a/assets/main.js b/assets/main.js
@@ -2,7 +2,6 @@
const currentDate = new Date();
const startDate = new Date(new Date().setFullYear(currentDate.getFullYear() - 1));
const spinner = document.getElementById('spinner');
-const statusDiv = document.getElementById('status');
const template = document.getElementById('chart-template');
const version = "v3.0.0";
@@ -130,10 +129,13 @@ document.getElementById('add-form').addEventListener('submit', function (event)
document.getElementById('name').value = '';
document.getElementById('url').value = 'https://';
vm.loadData();
+ document.getElementById('status').innerHTML = "";
} else if (data.status === 'unvalid-url') {
- statusDiv.insertAdjacentHTML('afterbegin', '<div class="alert alert-danger" role="alert">Unvalid URL. Please provide a valid URL.</div>');
+ document.getElementById('status').insertAdjacentHTML('afterbegin', '<div class="alert alert-danger" role="alert">Unvalid URL. Please provide a valid URL.</div>');
+ } else if (data.status === 'url-already-exists') {
+ document.getElementById('status').insertAdjacentHTML('afterbegin', '<div class="alert alert-danger" role="alert">URL already exists. Please delete before readding.</div>');
} else {
- statusDiv.insertAdjacentHTML('afterbegin', '<div class="alert alert-danger" role="alert">Error. Please try again.</div>');
+ document.getElementById('status').insertAdjacentHTML('afterbegin', '<div class="alert alert-danger" role="alert">Error. Please try again.</div>');
}
});
});
@@ -149,3 +151,4 @@ fetch('https://devshort.flokX.dev/api.php?mode=version¤t=' + version).then
document.getElementById('version-1').insertAdjacentHTML('beforeend', inner);
document.getElementById('version-2').insertAdjacentHTML('beforeend', inner);
});
+