Files
t3code/scripts/lib/android-apk-release.ts
T
bonzi a8b175132a
Fork Android APK / release (push) Has been cancelled
[verified] feat(mobile): install repository APK updates
2026-09-14 05:33:05 +00:00

33 lines
1.1 KiB
TypeScript

export function parseAndroidApkReleaseTag(tag: string): number {
const match = /^apk-([1-9]\d*)$/.exec(tag);
const versionCode = match ? Number(match[1]) : NaN;
if (!Number.isSafeInteger(versionCode) || versionCode > 2_100_000_000) {
throw new Error("APK release tags must be apk-<versionCode>, from 1 to 2100000000.");
}
return versionCode;
}
export function resolveAndroidApkRepository(repositoryUrl: string) {
const url = new URL(repositoryUrl);
const path = url.pathname.replace(/\/+$/, "").replace(/\.git$/, "");
const parts = path.split("/").filter(Boolean);
if (
url.protocol !== "https:" ||
url.username ||
url.password ||
url.search ||
url.hash ||
parts.length < 2
)
throw new Error(
"APK repository must be an HTTPS repository URL without credentials or query parameters.",
);
const repository = parts.slice(-2).join("/");
const basePath = parts.slice(0, -2).join("/");
const serverUrl = `${url.origin}${basePath ? `/${basePath}` : ""}`;
return {
releasesUrl: `${serverUrl}/${repository}/releases`,
apiUrl: `${serverUrl}/api/v1/repos/${repository}/releases`,
};
}