-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathdesktop.ts
More file actions
36 lines (32 loc) · 1.02 KB
/
Copy pathdesktop.ts
File metadata and controls
36 lines (32 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import type { HonoRequest } from "hono";
export function isFromDesktopSemver(
request: HonoRequest,
semver: readonly [number, number, number],
) {
const xCapVersion = request.header("X-Cap-Desktop-Version");
return xCapVersion ? isAtLeastSemver(xCapVersion, ...semver) : false;
}
export const UPLOAD_PROGRESS_VERSION = [0, 3, 68] as const;
export function isAtLeastSemver(
versionString: string,
major: number,
minor: number,
patch: number,
): boolean {
const match = versionString
.replace(/^v/, "")
.match(/^(\d+)\.(\d+)\.(\d+)(?:-(.+))?/);
if (!match) return false;
const [, vMajor, vMinor, vPatch, prerelease] = match;
const M = vMajor ? parseInt(vMajor, 10) || 0 : 0;
const m = vMinor ? parseInt(vMinor, 10) || 0 : 0;
const p = vPatch ? parseInt(vPatch, 10) || 0 : 0;
if (M > major) return true;
if (M < major) return false;
if (m > minor) return true;
if (m < minor) return false;
if (p > patch) return true;
if (p < patch) return false;
// Equal triplet: accept only non-prerelease
return !prerelease;
}