mirror of
https://github.com/outline/outline.git
synced 2026-11-20 21:23:06 +03:00
* Add missing JSDoc to exported members in app and server utils Documents all exported functions, classes, enums, and constants in app/utils and server/utils that were missing JSDoc, per the project documentation guidelines. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AsEQYA8zN813thxu7GjjzU * Use @returns tag to match codebase convention Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AsEQYA8zN813thxu7GjjzU --------- Co-authored-by: Claude <noreply@anthropic.com>
96 lines
2.9 KiB
TypeScript
96 lines
2.9 KiB
TypeScript
import { errToString } from "@shared/utils/error";
|
|
import { version } from "../../package.json";
|
|
import Logger from "@server/logging/Logger";
|
|
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);
|
|
}
|
|
|
|
/**
|
|
* Fetches the latest released version from Docker Hub and calculates how many
|
|
* versions behind the current installation is.
|
|
*
|
|
* @param currentVersion the currently installed version.
|
|
* @returns the latest version and the number of versions behind, or -1 if unknown.
|
|
*/
|
|
export async function getVersionInfo(currentVersion: string): Promise<{
|
|
latestVersion: string;
|
|
versionsBehind: number;
|
|
}> {
|
|
try {
|
|
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()) as {
|
|
results: { name: string }[];
|
|
next?: string | null;
|
|
};
|
|
|
|
// Map and filter the versions to keep only full releases
|
|
const pageVersions = data.results
|
|
.map((result) => 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
|
|
};
|
|
} catch (error) {
|
|
Logger.warn(
|
|
"Failed to fetch version information from Docker Hub. This is expected in isolated environments.",
|
|
{
|
|
currentVersion,
|
|
error: errToString(error),
|
|
}
|
|
);
|
|
|
|
// Return fallback values when external request fails
|
|
return {
|
|
latestVersion: currentVersion,
|
|
versionsBehind: -1,
|
|
};
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Returns the current version of the server from the package manifest.
|
|
*
|
|
* @returns the current version.
|
|
*/
|
|
export function getVersion(): string {
|
|
return version;
|
|
}
|