refactor: add checkUpdateAvailable to status endpoint

Signed-off-by: Ludovic Ortega <ludovic.ortega@adminafk.fr>
This commit is contained in:
Ludovic Ortega
2026-06-09 18:14:34 +02:00
parent 3c99cf23d1
commit 55cd7b397d
5 changed files with 59 additions and 47 deletions

View File

@@ -2150,10 +2150,18 @@ paths:
/status:
get:
summary: Get Seerr status
description: Returns the current Seerr status in a JSON object.
description: Returns the current Seerr status in a JSON object. updateAvailable and commitsBehind are omitted when checkUpdateAvailable is false.
security: []
tags:
- public
parameters:
- in: query
name: checkUpdateAvailable
description: If false, updateAvailable and commitsBehind will be omitted from the response. Defaults to true.
required: false
example: false
schema:
type: boolean
responses:
'200':
description: Returned status

View File

@@ -76,7 +76,7 @@ export interface CacheResponse {
export interface StatusResponse {
version: string;
commitTag: string;
updateAvailable: boolean;
commitsBehind: number;
updateAvailable?: boolean;
commitsBehind?: number;
restartRequired: boolean;
}

View File

@@ -48,40 +48,43 @@ const router = Router();
router.use(checkUser);
router.get<unknown, StatusResponse>('/status', async (req, res) => {
const githubApi = new GithubAPI();
const currentVersion = getAppVersion();
const commitTag = getCommitTag();
const checkUpdate = String(req.query.checkUpdateAvailable) !== 'false';
let updateAvailable = false;
let commitsBehind = 0;
if (currentVersion.startsWith('develop-') && commitTag !== 'local') {
const commits = await githubApi.getSeerrCommits();
if (checkUpdate) {
const githubApi = new GithubAPI();
if (commits.length) {
const filteredCommits = commits.filter(
(commit) => !commit.commit.message.includes('[skip ci]')
);
if (filteredCommits[0].sha !== commitTag) {
updateAvailable = true;
if (currentVersion.startsWith('develop-') && commitTag !== 'local') {
const commits = await githubApi.getSeerrCommits();
if (commits.length) {
const filteredCommits = commits.filter(
(commit) => !commit.commit.message.includes('[skip ci]')
);
if (filteredCommits[0].sha !== commitTag) {
updateAvailable = true;
}
const commitIndex = filteredCommits.findIndex(
(commit) => commit.sha === commitTag
);
if (updateAvailable) {
commitsBehind = commitIndex;
}
}
} else if (commitTag !== 'local') {
const releases = await githubApi.getSeerrReleases();
const commitIndex = filteredCommits.findIndex(
(commit) => commit.sha === commitTag
);
if (releases.length) {
const latestVersion = releases[0];
if (updateAvailable) {
commitsBehind = commitIndex;
}
}
} else if (commitTag !== 'local') {
const releases = await githubApi.getSeerrReleases();
if (releases.length) {
const latestVersion = releases[0];
if (!latestVersion.name.includes(currentVersion)) {
updateAvailable = true;
if (!latestVersion.name.includes(currentVersion)) {
updateAvailable = true;
}
}
}
}
@@ -89,8 +92,7 @@ router.get<unknown, StatusResponse>('/status', async (req, res) => {
return res.status(200).json({
version: getAppVersion(),
commitTag: getCommitTag(),
updateAvailable,
commitsBehind,
...(checkUpdate && { updateAvailable, commitsBehind }),
restartRequired: restartFlag.isSet(),
});
});

View File

@@ -27,7 +27,7 @@ const VersionStatus = ({ onClick }: VersionStatusProps) => {
const settings = useSettings();
const intl = useIntl();
const { data } = useSWR<StatusResponse>(
settings.currentSettings.versionCheck ? '/api/v1/status' : null,
`/api/v1/status?checkUpdateAvailable=${settings.currentSettings.versionCheck}`,
{
refreshInterval: 60 * 1000,
}
@@ -70,21 +70,23 @@ const VersionStatus = ({ onClick }: VersionStatusProps) => {
)}
<div className="flex min-w-0 flex-1 flex-col truncate px-2 last:pr-0">
<span className="font-bold">{versionStream}</span>
<span className="truncate">
{data.commitTag === 'local' ? (
'(⌐■_■)'
) : data.commitsBehind > 0 ? (
intl.formatMessage(messages.commitsbehind, {
commitsBehind: data.commitsBehind,
})
) : data.commitsBehind === -1 ? (
intl.formatMessage(messages.outofdate)
) : (
<code className="bg-transparent p-0">
{data.version.replace('develop-', '')}
</code>
)}
</span>
{data.commitsBehind !== undefined && (
<span className="truncate">
{data.commitTag === 'local' ? (
'(⌐■_■)'
) : data.commitsBehind > 0 ? (
intl.formatMessage(messages.commitsbehind, {
commitsBehind: data.commitsBehind,
})
) : data.commitsBehind === -1 ? (
intl.formatMessage(messages.outofdate)
) : (
<code className="bg-transparent p-0">
{data.version.replace('develop-', '')}
</code>
)}
</span>
)}
</div>
{data.updateAvailable && <ArrowUpCircleIcon className="h-6 w-6" />}
</Link>

View File

@@ -24,7 +24,7 @@ const StatusChecker = () => {
const settings = useSettings();
const { hasPermission } = useUser();
const { data, error } = useSWR<StatusResponse>(
settings.currentSettings.versionCheck ? '/api/v1/status' : null,
'/api/v1/status?checkUpdateAvailable=false',
{
refreshInterval: 60 * 1000,
}