Support Linux and Mac versions parsing

This commit is contained in:
Alexander Borsuk 2023-03-29 16:41:46 +02:00 committed by Alexander Borsuk
parent 535a7e1f56
commit 64a0fc7363
2 changed files with 21 additions and 11 deletions

View file

@ -16,7 +16,10 @@ export function parseDataVersion(strDataVersion: string | null): number | null {
// 2022.11.20 for iOS versions released before November 21 (without donate menu)
// 2022.11.24-4-ios for newer iOS versions (with donate menu)
// 2022.12.24-10-Google for Android
const VERSION_RE = /(\d{4}).(\d{1,2}).(\d{1,2})(?:$|-(\d{1,9})(?:-([^-]+))?)/;
// 2022.12.24-3-3f4ca43-Linux or 2022.12.24-3-3f4ca43-dirty-Linux for Linux
// 2022.12.24-3-3f4ca43-Darwin for Mac
const VERSION_RE =
/(?<year>\d{4})\.(?<month>\d{1,2})\.(?<day>\d{1,2})(?:$|-(?<build>[0-9]+)(?:-[0-9a-f]+)?(?:-dirty)?-(?<flavor>[A-Za-z3264]+))/;
// Returns code like 221224 for both platforms, build and flavor for Android and newer iOS versions.
export function parseAppVersion(
versionName: string | null,
@ -26,32 +29,32 @@ export function parseAppVersion(
}
const m = versionName.match(VERSION_RE);
if (m === null || m.length < 4) {
if (m === null || m.length < 4 || !m.groups) {
return null;
}
const yyyy = parseInt(m[1]);
const yyyy = parseInt(m.groups.year);
if (Number.isNaN(yyyy) || yyyy > 2099 || yyyy < 2022) {
return null;
}
const mm = parseInt(m[2]);
const mm = parseInt(m.groups.month);
if (Number.isNaN(mm) || mm > 12 || mm < 1) {
return null;
}
const dd = parseInt(m[3]);
const dd = parseInt(m.groups.day);
if (Number.isNaN(dd) || dd > 31 || dd < 1) {
return null;
}
const code = parseInt(String(yyyy % 100) + String(mm).padStart(2, '0') + String(dd).padStart(2, '0'));
// Older iOS versions without donate button.
if (m[4] === undefined) {
if (!m.groups.build) {
return { code: code };
}
const buildNumber = parseInt(m[4]);
const buildNumber = parseInt(m.groups.build);
const build = Number.isNaN(buildNumber) ? 0 : buildNumber;
// 'ios' for iOS devices.
const flavor = (m[5] !== undefined && m[5].toLowerCase()) || undefined;
const flavor = (m.groups.flavor !== undefined && m.groups.flavor.toLowerCase()) || undefined;
return {
code: code,

View file

@ -24,12 +24,19 @@ describe('parseAppVersion', () => {
'2022.08.01': { code: 220801 },
// Newer iOS releases with donate menu
'2022.11.25-5-ios': { code: 221125, build: 5, flavor: 'ios' },
'2022.08.01-1': { code: 220801, build: 1 },
// There were no such versions in production.
'2022.08.01-1': null,
'2022.08.01-1-Google': { code: 220801, build: 1, flavor: 'google' },
// -debug is ignored
'2022.08.01-1-Google-debug': { code: 220801, build: 1, flavor: 'google' },
'2022.1.1-0': { code: 220101, build: 0 },
'2099.12.31-999999999': { code: 991231, build: 999999999 },
// TODO: Fix regexp. Not it should not happen in production.
//'2022.08.01-1-fd-debug': { code: 220801, build: 1, flavor: 'fd' },
'2022.1.1-0': null,
'2099.12.31-999999999': null,
'2023.03.22-1-4fac32de-Linux': { code: 230322, build: 1, flavor: 'linux' },
'2023.03.22-1-4fac32de-dirty-Linux': { code: 230322, build: 1, flavor: 'linux' },
'2023.03.22-1-4fac32de-Darwin': { code: 230322, build: 1, flavor: 'darwin' },
'2023.03.22-1-4fac32de-dirty-Darwin': { code: 230322, build: 1, flavor: 'darwin' },
'2021.01.31-1': null,
'2100.01.31-1': null,
'2022.00.31-1': null,