Add restAPI doc link when svc is active

This commit is contained in:
billz 2024-03-09 09:25:02 +01:00
parent 1e840abbaf
commit f81c68de26
2 changed files with 24 additions and 2 deletions

View file

@ -49,11 +49,18 @@ function DisplayRestAPI()
array_shift($output);
$serviceLog = implode("\n", $output);
if ($serviceStatus == "up") {
$docUrl = getDocUrl();
$faicon = "<i class=\"text-gray-500 fas fa-external-link-alt ml-1\"></i>";
$docMsg = sprintf(_("RestAPI docs are accessible <a href=\"%s\" target=\"_blank\">here%s</a>"),$docUrl, $faicon);
}
echo renderTemplate("restapi", compact(
"status",
"apiKey",
"serviceStatus",
"serviceLog"
"serviceLog",
"docMsg"
));
}
@ -72,3 +79,13 @@ function saveAPISettings($status, $apiKey, $dotenv)
return $status;
}
// Returns a url for fastapi's automatic docs
function getDocUrl()
{
$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https://' : 'http://';
$server_name = $_SERVER['SERVER_NAME'];
$port = 8081;
$url = $protocol . $server_name .':'. $port . '/docs';
return $url;
}

View file

@ -1,8 +1,13 @@
<div class="tab-pane active" id="restapisettings">
<h4 class="mt-3"><?php echo ("RestAPI settings") ;?></h4>
<div class="row">
<div class="form-group col-lg-12 mt-3">
<div class="form-group col-lg-12 mt-2">
<div class="row">
<div class="col-md-6">
<?php echo $docMsg; ?>
</div>
</div>
<div class="row mt-3">
<div class="form-group col-md-6" required>
<label for="txtapikey"><?php echo _("API Key"); ?></label>
<div class="input-group">