From d8dfcd84b0bf4b22bc17d1aed7ce7f92a0eb2505 Mon Sep 17 00:00:00 2001 From: Austin Best Date: Fri, 27 Dec 2024 20:29:40 -0500 Subject: [PATCH] Adjustments to the test/save starr logic when using a bad base url --- root/app/www/public/ajax/starr.php | 22 ++++++++++++++++------ root/app/www/public/js/starr.js | 6 +++--- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/root/app/www/public/ajax/starr.php b/root/app/www/public/ajax/starr.php index e72baf1..c19cc59 100644 --- a/root/app/www/public/ajax/starr.php +++ b/root/app/www/public/ajax/starr.php @@ -26,7 +26,11 @@ if ($test['code'] != 200) { $error = 'Failed to connect with code: ' . $test['code']; } else { - $result = 'Connection successful to ' . $app . ': Instance ' . $test['response']['instanceName']; + if (str_contains($test['response'], 'doctype')) { + $error = 'The starr app returned HTML, this typically happens with a bad base URL.'; + } else { + $result = 'Connection successful to ' . $app . ': Instance ' . $test['response']['instanceName']; + } } echo json_encode(['error' => $error, 'result' => $result]); @@ -57,7 +61,11 @@ $name = 'ERROR'; if ($test['code'] == 200) { - $name = $test['response']['instanceName']; + if (str_contains($test['response'], 'doctype')) { + $error = 'The starr app returned HTML, this typically happens with a bad base URL.'; + } else { + $name = $test['response']['instanceName']; + } } $fields = [ @@ -68,10 +76,12 @@ 'password' => rawurldecode($_POST['password']) ]; - if ($_POST['starrId'] == '99') { - $error = $proxyDb->addStarrApp($app, $fields); - } else { - $error = $proxyDb->updateStarrApp($_POST['starrId'], $fields); + if (!$error) { + if ($_POST['starrId'] == '99') { + $error = $proxyDb->addStarrApp($app, $fields); + } else { + $error = $proxyDb->updateStarrApp($_POST['starrId'], $fields); + } } echo $error; diff --git a/root/app/www/public/js/starr.js b/root/app/www/public/js/starr.js index fa176a2..cd11526 100644 --- a/root/app/www/public/js/starr.js +++ b/root/app/www/public/js/starr.js @@ -21,12 +21,12 @@ function testStarr(starrId, app) data: '&m=testStarr&starrId=' + starrId + '&url=' + $('#instance-url-' + starrId).val() + '&apikey=' + apikey + '&app=' + app, dataType: 'json', success: function (resultData) { - let type = 'success'; if (resultData.error) { - type = 'error'; + toast('Starr test', resultData.error, 'error'); + return; } - toast('Starr test', resultData.result, type); + toast('Starr test', resultData.result, 'success'); } }); }