test data before use

This commit is contained in:
Aliberk Sandıkçı 2024-01-08 19:05:46 +03:00
parent 041b6a2634
commit 412bcc1035
Signed by: asandikci
GPG Key ID: 25C67A03B5666BC1
2 changed files with 36 additions and 3 deletions

View File

@ -106,12 +106,28 @@
<script>
function updateData() {
xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var response = xmlHttp.responseText
if (response.includes("parseError") ){
console.error("VERİLER YANLIŞ ŞEKİLDE GİRİLMİŞ, GÖTÜNÜ SİKEYİM KELO");
console.warn(response);
} else if (response.includes("fileError")){
console.error("VERİ DOSYASI SUNUCUDA BULUNAMADI, SUNUCUYU KONTROL EDİNİZ");
console.warn(response);
} else if (response.includes("success")) {
console.info("VERİLER BAŞARIYLA GÜNCELLENDİ")
} else {
console.warn("VERİ GÜNCELLENİRKEN BİR HATA OLUŞTU, SAYFAYI YENİLEMEYİ DENEYİN");
}
}
};
params = "updateData=yes";
xmlHttp.open("POST", "src/server.php", true);
xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xmlHttp.send(params);
flag = true;
return "UPDATED DATA FROM SERVER!"
return;
}
</script>
<script>

View File

@ -10,13 +10,29 @@ $parser = new Toml();
$dock_local_test = 1;
# Fetch Remote data and update data.toml (running each 10 min with cronjob)
function testData($toml)
{
global $parser;
try {
$array = $parser::Parse($toml);
} catch (Exception $e) {
$ans = 'Caught exception: ' . $e->getMessage() . "\n";
return $ans;
}
return 0;
}
function updateRemoteData()
{
global $DATAACCESS_TOKEN;
global $APP_NAME;
$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.";
echo "fileError: Could not read the file or could not get the file from server";
return;
} else if (testData($string) != 0) {
echo "parseError: " . testData($string);
return;
} else {
$file = __DIR__ . "/../data.toml";
file_put_contents($file, $string, LOCK_EX);
@ -25,6 +41,7 @@ function updateRemoteData()
chown("$file", $APP_NAME);
parseTOML(); // not necessary
echo "success";
}
@ -193,4 +210,4 @@ function parseTOML()
if ($_POST['updateData'] != null && $_POST['updateData'] == "yes") {
updateRemoteData();
}
}