mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-02 19:42:51 +08:00
Check official GitHub Releases, require SHA256SUMS, safely extract and swap release-package code, roll back on failed health checks, and persist task state across restarts. Docker and source deployments stay check-only. Add updater tests, route security tests and five-language admin copy.
39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
/** Stable semantic versions only. Pre-release/rolling channels are deliberate non-goals. */
|
|
export interface StableVersion {
|
|
major: number;
|
|
minor: number;
|
|
patch: number;
|
|
text: string;
|
|
}
|
|
|
|
const STABLE = /^(\d{1,6})\.(\d{1,6})\.(\d{1,6})$/;
|
|
|
|
export function parseStableVersion(value: unknown): StableVersion | null {
|
|
if (typeof value !== "string") return null;
|
|
const match = STABLE.exec(value.trim());
|
|
if (!match) return null;
|
|
const [, major, minor, patch] = match;
|
|
return { major: Number(major), minor: Number(minor), patch: Number(patch), text: `${Number(major)}.${Number(minor)}.${Number(patch)}` };
|
|
}
|
|
|
|
/** `v1.2.3` is the only accepted release tag shape. */
|
|
export function parseReleaseTag(value: unknown): StableVersion | null {
|
|
if (typeof value !== "string" || !value.startsWith("v")) return null;
|
|
return parseStableVersion(value.slice(1));
|
|
}
|
|
|
|
export function isValidVersion(value: unknown): value is string {
|
|
return parseStableVersion(value) !== null;
|
|
}
|
|
|
|
export function compareVersions(left: string, right: string): number {
|
|
const a = parseStableVersion(left);
|
|
const b = parseStableVersion(right);
|
|
if (!a || !b) return 0;
|
|
return a.major - b.major || a.minor - b.minor || a.patch - b.patch;
|
|
}
|
|
|
|
export function isNewerVersion(candidate: string, current: string): boolean {
|
|
return compareVersions(candidate, current) > 0;
|
|
}
|