Skip to content

Commit

Permalink
Adjustments to the test/save starr logic when using a bad base url
Browse files Browse the repository at this point in the history
  • Loading branch information
austinwbest committed Dec 28, 2024
1 parent a8ab6cc commit d8dfcd8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
22 changes: 16 additions & 6 deletions root/app/www/public/ajax/starr.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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 = [
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions root/app/www/public/js/starr.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
});
}
Expand Down

0 comments on commit d8dfcd8

Please sign in to comment.