Skip to content

Commit d8dfcd8

Browse files
committed
Adjustments to the test/save starr logic when using a bad base url
1 parent a8ab6cc commit d8dfcd8

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

root/app/www/public/ajax/starr.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@
2626
if ($test['code'] != 200) {
2727
$error = 'Failed to connect with code: ' . $test['code'];
2828
} else {
29-
$result = 'Connection successful to ' . $app . ': Instance ' . $test['response']['instanceName'];
29+
if (str_contains($test['response'], 'doctype')) {
30+
$error = 'The starr app returned HTML, this typically happens with a bad base URL.';
31+
} else {
32+
$result = 'Connection successful to ' . $app . ': Instance ' . $test['response']['instanceName'];
33+
}
3034
}
3135

3236
echo json_encode(['error' => $error, 'result' => $result]);
@@ -57,7 +61,11 @@
5761
$name = 'ERROR';
5862

5963
if ($test['code'] == 200) {
60-
$name = $test['response']['instanceName'];
64+
if (str_contains($test['response'], 'doctype')) {
65+
$error = 'The starr app returned HTML, this typically happens with a bad base URL.';
66+
} else {
67+
$name = $test['response']['instanceName'];
68+
}
6169
}
6270

6371
$fields = [
@@ -68,10 +76,12 @@
6876
'password' => rawurldecode($_POST['password'])
6977
];
7078

71-
if ($_POST['starrId'] == '99') {
72-
$error = $proxyDb->addStarrApp($app, $fields);
73-
} else {
74-
$error = $proxyDb->updateStarrApp($_POST['starrId'], $fields);
79+
if (!$error) {
80+
if ($_POST['starrId'] == '99') {
81+
$error = $proxyDb->addStarrApp($app, $fields);
82+
} else {
83+
$error = $proxyDb->updateStarrApp($_POST['starrId'], $fields);
84+
}
7585
}
7686

7787
echo $error;

root/app/www/public/js/starr.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ function testStarr(starrId, app)
2121
data: '&m=testStarr&starrId=' + starrId + '&url=' + $('#instance-url-' + starrId).val() + '&apikey=' + apikey + '&app=' + app,
2222
dataType: 'json',
2323
success: function (resultData) {
24-
let type = 'success';
2524
if (resultData.error) {
26-
type = 'error';
25+
toast('Starr test', resultData.error, 'error');
26+
return;
2727
}
2828

29-
toast('Starr test', resultData.result, type);
29+
toast('Starr test', resultData.result, 'success');
3030
}
3131
});
3232
}

0 commit comments

Comments
 (0)