devshort

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

commit e366fa2da0714a7c095c7981cf1079c9e743ce5d
parent 9c457e1a391e3e153ff2615985354ba9fa82d6cb
Author: Florian <flokX@users.noreply.github.com>
Date:   Sun, 19 Jan 2020 10:59:36 +0100

Use ISO timestamps

* Breaking change, when upgrading to v3.0.0 conversion of the stats.json is required

Diffstat:
Madmin.php | 2+-
Massets/main.js | 8++++----
Mindex.php | 4++--
Mredirect.php | 6+++---
4 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/admin.php b/admin.php @@ -39,7 +39,7 @@ if (isset($_GET["delete"]) || isset($_GET["add"])) { $stats_content[$filtered["name"]] = array(); } file_put_contents($config_path, json_encode($config_content, JSON_PRETTY_PRINT)); - file_put_contents($stats_path, json_encode($stats_content)); + file_put_contents($stats_path, json_encode($stats_content, JSON_PRETTY_PRINT)); header("Content-Type: application/json"); echo "{\"status\": \"successful\"}"; exit; diff --git a/assets/main.js b/assets/main.js @@ -33,13 +33,13 @@ Vue.component('chart', { methods: { render: function () { let dataset = []; - for (let [unixTimestamp, count] of Object.entries(this.stats)) { - let timestamp = new Date(unixTimestamp * 1000); - if (((currentDate - timestamp) / (60 * 60 * 24 * 1000)) <= 7) { + for (let [isoDate, count] of Object.entries(this.stats)) { + let date = new Date(isoDate); + if (((currentDate - date) / (60 * 60 * 24 * 1000)) <= 7) { this.accessCount.sevenDays += count; } this.accessCount.total += count; - dataset.push({ x: timestamp, y: count }); + dataset.push({ x: date, y: count }); } new frappe.Chart('div#' + this.chartId, { type: 'heatmap', diff --git a/index.php b/index.php @@ -8,8 +8,8 @@ $stats_path = implode(DIRECTORY_SEPARATOR, array(__DIR__, "data", "stats.json")) $stats_content = json_decode(file_get_contents($stats_path), true); // Count the access -$stats_content["Index"][mktime(0, 0, 0)] += 1; -file_put_contents($stats_path, json_encode($stats_content)); +$stats_content["Index"][date("Y-m-d")] += 1; +file_put_contents($stats_path, json_encode($stats_content, JSON_PRETTY_PRINT)); // Generate custom buttons for the footer $links_string = ""; diff --git a/redirect.php b/redirect.php @@ -18,9 +18,9 @@ $stats_content = json_decode(file_get_contents($stats_path), true); // Count the access to the given $name function count_access($name) { global $stats_path, $stats_content; - - $stats_content[$name][mktime(0, 0, 0)] += 1; - file_put_contents($stats_path, json_encode($stats_content)); + + $stats_content[$name][date("Y-m-d")] += 1; + file_put_contents($stats_path, json_encode($stats_content, JSON_PRETTY_PRINT)); } if (array_key_exists($short, $config_content["shortlinks"])) {