mirror of
https://github.com/outline/outline.git
synced 2026-05-08 02:50:30 -05:00
Feat/installation info endpoint (#7744)
* feat: add installation.info endpoint using DockerHub API * feat: UI use an server-side API to show version info * fix: review fixes * test: installation.info endpoint * feat: filtering pre-releases in installation.info endpoint * fix: change fetch to ApiClient usage for getting version info * Undo translation change --------- Co-authored-by: Tom Moor <tom.moor@gmail.com>
This commit is contained in:
committed by
GitHub
parent
fe33871dfe
commit
2e1a827157
@@ -0,0 +1,62 @@
|
||||
import { version } from "../../package.json";
|
||||
import fetch from "./fetch";
|
||||
|
||||
const dockerhubLink =
|
||||
"https://hub.docker.com/v2/repositories/outlinewiki/outline";
|
||||
|
||||
function isFullReleaseVersion(versionName: string): boolean {
|
||||
const releaseRegex = /^(version-)?\d+\.\d+\.\d+$/; // Matches "N.N.N" or "version-N.N.N" for dockerhub releases before v0.56.0"
|
||||
return releaseRegex.test(versionName);
|
||||
}
|
||||
|
||||
export async function getVersionInfo(currentVersion: string): Promise<{
|
||||
latestVersion: string;
|
||||
versionsBehind: number;
|
||||
}> {
|
||||
let allVersions: string[] = [];
|
||||
let latestVersion: string | null = null;
|
||||
let nextUrl: string | null =
|
||||
dockerhubLink + "/tags?name=&ordering=last_updated&page_size=100";
|
||||
|
||||
// Continue fetching pages until the required versions are found or no more pages
|
||||
while (nextUrl) {
|
||||
const response = await fetch(nextUrl);
|
||||
const data = await response.json();
|
||||
|
||||
// Map and filter the versions to keep only full releases
|
||||
const pageVersions = data.results
|
||||
.map((result: any) => result.name)
|
||||
.filter(isFullReleaseVersion);
|
||||
|
||||
allVersions = allVersions.concat(pageVersions);
|
||||
|
||||
// Set the latest version if not already set
|
||||
if (!latestVersion && pageVersions.length > 0) {
|
||||
latestVersion = pageVersions[0];
|
||||
}
|
||||
|
||||
// Check if the current version is found
|
||||
const currentIndex = allVersions.findIndex(
|
||||
(version: string) => version === currentVersion
|
||||
);
|
||||
|
||||
if (currentIndex !== -1) {
|
||||
const versionsBehind = currentIndex; // The number of versions behind
|
||||
return {
|
||||
latestVersion: latestVersion || currentVersion, // Fallback to current if no latest found
|
||||
versionsBehind,
|
||||
};
|
||||
}
|
||||
|
||||
nextUrl = data.next || null;
|
||||
}
|
||||
|
||||
return {
|
||||
latestVersion: latestVersion || currentVersion,
|
||||
versionsBehind: -1, // Return -1 if current version is not found
|
||||
};
|
||||
}
|
||||
|
||||
export function getVersion(): string {
|
||||
return version;
|
||||
}
|
||||
Reference in New Issue
Block a user