devshort

private self-hosted shortlink service
git clone https://git.clttr.info/devshort.git
Log (Feed) | Files | Refs (Tags) | README | LICENSE

commit a0b65e8d50a38c27636eece762a0e445a4f7657f
parent 86c32aa965348b816f0c62092612cb8787033cb5
Author: Florian <flokX@users.noreply.github.com>
Date:   Thu, 26 Dec 2019 18:00:21 +0100

Add stats.json proxy

The data directory is not accessible via clientside JavaScript. Add a proxy to get the stats.json content via the admin.php.

Diffstat:
Madmin.php | 7+++++++
Massets/main.js | 5+----
2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/admin.php b/admin.php @@ -14,6 +14,13 @@ if (!isset($_SESSION["user_authenticated"])) { exit; } +// Deliver stats.json content for the program (make AJAX calls and charts reloading possible) +if (isset($_GET["get_stats"])) { + header("Content-Type: application/json"); + readfile($stats_path); + exit; +} + // Filter the names that the admin interface doesn't break function filter_name($nameRaw) { $name = filter_var($nameRaw, FILTER_SANITIZE_STRING); diff --git a/assets/main.js b/assets/main.js @@ -75,10 +75,7 @@ function getCharts() { while (chartsDiv.firstChild) { chartsDiv.firstChild.remove(); } - fetch('../data/stats.json', { - cache: 'no-cache', - credentials: 'same-origin' - }).then(function (response) { + fetch('admin.php?get_stats').then(function (response) { return response.json(); }).then(function (json) { for (let [name, data] of Object.entries(json)) {