From 18c28057687c4e48832d21b42b371d5310f27b92 Mon Sep 17 00:00:00 2001 From: asandikci Date: Sun, 7 Jan 2024 12:47:16 +0300 Subject: [PATCH] update data from server --- .gitignore | 1 + index.php | 26 ++++++++++++++------------ src/server.php | 24 +++++++++++++++++++++--- 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index cc230e9..381ce24 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ build/* *.tar.gz *.zip /vendor/ +config.php \ No newline at end of file diff --git a/index.php b/index.php index 1ea4d22..49e7533 100644 --- a/index.php +++ b/index.php @@ -64,7 +64,6 @@ } document.getElementById("tebriks").style.display = "none"; if (localStorage.getItem("win") != null && localStorage.getItem("win") === "winned") { - console.log(localStorage.getItem("win")); document.getElementById("tebriks").style.display = "block"; document.getElementById("tebriks").innerHTML = "Tebrikler, günün şanslı kişisini buldun!" } @@ -76,14 +75,16 @@ } else { latest_visit = localStorage.getItem("latest_visit"); if (isSameDay(new Date(latest_visit), date)) { - console.log("same day!"); + console.debug("Kullanıcı Son Girişi İle Aynı Günde"); } else { - console.log("different day!"); + console.debug("Kullanıcı Farklı Bir Günde Giriş Yaptı, Statlar Sıfırlanıyor"); localStorage.removeItem("guesses"); + localStorage.removeItem("latest_guess"); + localStorage.removeItem("win"); } localStorage.setItem("latest_visit", date); } - + current_guess = "); + ?>); localStorage.setItem("guesses", JSON.stringify(gj)); } @@ -150,7 +152,7 @@ table.appendChild(tr); indata = JSON.parse(gj["Values"][i]); - console.warn(indata); + // console.warn(indata); for (const key in criterias) { if (innerFlag) crit_num++; const td = document.createElement("td"); @@ -183,10 +185,10 @@ } } - console.log(gj); + // console.log(gj); if (crit_num == (true_num + 1)) // +1 isim_soyisim sayılmadığı için { - console.warn(crit_num, true_num); + // console.warn(crit_num, true_num); document.getElementById("tebriks").style.display = "block"; document.getElementById("tebriks").innerHTML = "Tebrikler, günün şanslı kişisini buldun!" localStorage.setItem("win", "winned"); @@ -217,7 +219,7 @@ // UPDATES const updates = ; document.getElementById("latest-data").innerHTML = updates[0]; - console.log("günün kişisi güncellenme zamanı: " + updates[1]); + console.info("Günün Kişisi, Son Güncelleme Zamanı: " + updates[1]); /// AUTOCOMPLETE /// diff --git a/src/server.php b/src/server.php index 57545b8..e846b77 100644 --- a/src/server.php +++ b/src/server.php @@ -3,9 +3,11 @@ use Yosymfony\Toml\Toml; include 'todays.php'; +include '../config.php'; require __DIR__ . '/../vendor/autoload.php'; $parser = new Toml(); +$dock_local_test = 1; # Fetch remote data each 1 hour function updateRemoteData() @@ -14,7 +16,16 @@ function updateRemoteData() # GET FROM GIT WITH ACCESS TOKEN AND SAVE TO data.toml - # MAKE SURE FILE IS CHMOD 600 AND NOT ACCESSIBLE FROM USERSIDE !!! + global $DATAACCESS_TOKEN; + $string = file_get_contents("https://git.aliberksandikci.com.tr/api/v1/repos/ifl/YurdleBackend/raw/data.toml?access_token=" . $DATAACCESS_TOKEN); + if ($string === FALSE) { + echo "Could not read the file."; + } else { + $file = __DIR__ . "/../data.toml"; + file_put_contents($file, $string, LOCK_EX); + } + + # REVIEW MAKE SURE FILE IS CHMOD 600 AND NOT ACCESSIBLE FROM USERSIDE !!! parseTOML(); # parse again after update @@ -186,8 +197,15 @@ function getAPersonStats($person) function parseTOML() { global $parser; - $array = $parser::ParseFile("data.toml"); - return $array; + global $dock_local_test; + if ($dock_local_test) { + $array = $parser::ParseFile("../data.toml"); + return $array; + } else { + $array = $parser::ParseFile("data.toml"); + return $array; + } } +updateRemoteData(); comparePerson('aliberk_sandikci24');