commit 2a38e8b0535925adff77b470171e5c09f789af46
parent 488b4f78c329c8e3289a2033265b7e14fd1601db
Author: Florian <flokX@users.noreply.github.com>
Date: Tue, 28 Jan 2020 10:44:04 +0100
Merge pull request #19 from guzzisti/check_existing_urls
avoid readding an already existing url cause this deletes that stats
Diffstat:
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/admin.php b/admin.php
@@ -35,6 +35,10 @@ 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>');
}
});
});