List web updates as unavailable if the updater container isn't running.

This commit is contained in:
Buster Neece 2023-08-21 01:28:13 -05:00
parent 13d1e5c216
commit 9f5dbcb10f
No known key found for this signature in database
3 changed files with 36 additions and 7 deletions

View File

@ -159,6 +159,7 @@ import {useNotify} from "~/functions/useNotify";
import {useAxios} from "~/vendor/axios";
import {useSweetAlert} from "~/vendor/sweetalert";
import CardPage from "~/components/Common/CardPage.vue";
import {getApiUrl} from "~/router";
const props = defineProps({
releaseChannel: {
@ -171,16 +172,14 @@ const props = defineProps({
return {};
}
},
updatesApiUrl: {
type: String,
required: true
},
enableWebUpdates: {
type: Boolean,
required: true
}
});
const updatesApiUrl = getApiUrl('/admin/updates');
const updateInfo = ref(props.initialUpdateInfo);
const {$gettext} = useTranslate();
@ -204,7 +203,7 @@ const {axios} = useAxios();
const checkForUpdates = () => {
wrapWithLoading(
axios.get(props.updatesApiUrl)
axios.get(updatesApiUrl.value)
).then((resp) => {
updateInfo.value = resp.data;
});

View File

@ -9,6 +9,7 @@ use App\Container\SettingsAwareTrait;
use App\Controller\SingleActionInterface;
use App\Http\Response;
use App\Http\ServerRequest;
use App\Service\WebUpdater;
use App\Version;
use Psr\Http\Message\ResponseInterface;
@ -18,7 +19,8 @@ final class UpdatesAction implements SingleActionInterface
use SettingsAwareTrait;
public function __construct(
private readonly Version $version
private readonly Version $version,
private readonly WebUpdater $webUpdater,
) {
}
@ -31,11 +33,16 @@ final class UpdatesAction implements SingleActionInterface
$router = $request->getRouter();
$enableWebUpdates = $this->environment->enableWebUpdater();
if ($enableWebUpdates && !$this->webUpdater->ping()) {
$enableWebUpdates = false;
}
return $response->withJson([
'releaseChannel' => $this->version->getReleaseChannelEnum()->value,
'initialUpdateInfo' => $settings->getUpdateResults(),
'updatesApiUrl' => $router->named('api:admin:updates'),
'enableWebUpdates' => $this->environment->enableWebUpdater(),
'enableWebUpdates' => $enableWebUpdates,
]);
}
}

View File

@ -6,6 +6,7 @@ namespace App\Service;
use App\Container\EnvironmentAwareTrait;
use RuntimeException;
use Throwable;
final class WebUpdater
{
@ -24,6 +25,28 @@ final class WebUpdater
return $this->environment->enableWebUpdater();
}
public function ping(): bool
{
if (!$this->isSupported()) {
return false;
}
try {
$client = $this->guzzleFactory->buildClient();
$client->get(
'http://updater:8080/',
[
'http_errors' => false,
'timeout' => 5,
]
);
return true;
} catch (Throwable) {
return false;
}
}
public function triggerUpdate(): void
{
if (!$this->isSupported()) {