Tweaks to showing new version available

- Added frontend translation for english
- Moved frontend api logic to hook and backend api space
- Added swagger schema for the new api endpoint
- Moved backend logic to its own internal file
- Added user agent header to github api check
- Added cypress integration test for version check api
- Added a memory cache item from github check to avoid hitting it too
  much
This commit is contained in:
Jamie Curnow
2025-11-13 11:17:44 +10:00
parent 8838dabe8a
commit cf7306e766
15 changed files with 200 additions and 95 deletions

View File

@@ -1,11 +1,9 @@
import { useEffect, useState } from "react";
import { useHealth } from "src/hooks";
import { useCheckVersion, useHealth } from "src/hooks";
import { T } from "src/locale";
export function SiteFooter() {
const health = useHealth();
const [latestVersion, setLatestVersion] = useState<string | null>(null);
const [isNewVersionAvailable, setIsNewVersionAvailable] = useState(false);
const { data: versionData } = useCheckVersion();
const getVersion = () => {
if (!health.data) {
@@ -15,25 +13,6 @@ export function SiteFooter() {
return `v${v.major}.${v.minor}.${v.revision}`;
};
useEffect(() => {
const checkForUpdates = async () => {
try {
const response = await fetch("/api/version/check");
if (response.ok) {
const data = await response.json();
setLatestVersion(data.latest);
setIsNewVersionAvailable(data.updateAvailable);
}
} catch (error) {
console.debug("Could not check for updates:", error);
}
};
if (health.data) {
checkForUpdates();
}
}, [health.data]);
return (
<footer className="footer d-print-none py-3">
<div className="container-xl">
@@ -77,16 +56,16 @@ export function SiteFooter() {
{getVersion()}{" "}
</a>
</li>
{isNewVersionAvailable && latestVersion && (
{versionData?.updateAvailable && versionData?.latest && (
<li className="list-inline-item">
<a
href={`https://github.com/NginxProxyManager/nginx-proxy-manager/releases/tag/${latestVersion}`}
href={`https://github.com/NginxProxyManager/nginx-proxy-manager/releases/tag/${versionData.latest}`}
className="link-warning fw-bold"
target="_blank"
rel="noopener"
title={`New version ${latestVersion} is available`}
title={`New version ${versionData.latest} is available`}
>
Update Available: ({latestVersion})
<T id="update-available" data={{ latestVersion: versionData.latest }} />
</a>
</li>
)}