From b1063f5057e2a31fa54c425affba45f622ec8597 Mon Sep 17 00:00:00 2001 From: zontreck Date: Sun, 25 May 2025 13:33:27 -0700 Subject: [PATCH] Attempt to fix web viewer being unable to load NBT --- lib/consts.dart | 2 +- lib/data.dart | 8 +++++++- pubspec.yaml | 2 +- server/php/timetrack.php | 11 +++++++---- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/consts.dart b/lib/consts.dart index 4c7707b..09ea71f 100644 --- a/lib/consts.dart +++ b/lib/consts.dart @@ -9,7 +9,7 @@ class TTConsts { static get SESSION_SERVER => "https://api.zontreck.com/timetrack/$UPDATE_CHANNEL/timetrack.php"; - static const VERSION = "1.0.0-beta.17"; + static const VERSION = "1.0.0-beta.18"; static bool UPDATE_AVAILABLE = false; static UpdateChannel UPDATE_CHANNEL = UpdateChannel.beta; diff --git a/lib/data.dart b/lib/data.dart index 76d7bb3..54f8845 100644 --- a/lib/data.dart +++ b/lib/data.dart @@ -264,6 +264,7 @@ class SessionData { Map payload = { "cmd": "create", + "type": "nbt", "data": base64Encoder.encode(nbtData), }; @@ -444,6 +445,7 @@ class SessionData { if (cType == "application/json") { return LoadData(reply.data as Map); } else if (cType == "application/nbt") { + print("Data is in NBT Format"); Uint8List lst = base64Encoder.decode(reply.data as String); // Convert this to a CompoundTag CompoundTag ct = await NbtIo.readFromStream(lst) as CompoundTag; @@ -451,7 +453,11 @@ class SessionData { return true; } else return false; - } catch (E) { + } catch (E, stack) { + print(E); + + print(stack); + return false; } } diff --git a/pubspec.yaml b/pubspec.yaml index 3897d8b..0db30e5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.0.0-beta.17 +version: 1.0.0-beta.18 environment: sdk: ^3.7.2 diff --git a/server/php/timetrack.php b/server/php/timetrack.php index fdabe93..c89c332 100644 --- a/server/php/timetrack.php +++ b/server/php/timetrack.php @@ -35,10 +35,9 @@ switch($jsx['cmd']) { $stmt->close(); // Prepare data as JSON and insert into `data` table - if(is_array($jsx['data'])) { + if($jsx['type'] == "json") { $data = json_encode($jsx['data']); - } // else: The data is binary or NBT. - else { + }else if($jsx ['type'] == "nbt") { $data = base64_decode($jsx['data']); } @@ -79,12 +78,16 @@ switch($jsx['cmd']) { $stmt->close(); // Decode the JSON blob (optional — if you want raw JSON output) - if(substr($sessionData, 0, 1) == "{") { + $testDecoded = json_decode($sessionData, true); + if(json_last_error() == JSON_ERROR_NONE) { + header("Content-Type: application/json"); die($sessionData); + }else { header("Content-Type: application/nbt"); die(base64_encode($sessionData)); + //die($sessionData); } break; }