Support server-determined build expiration
This commit is contained in:
parent
a04f9a0e51
commit
d87335f5a6
14 changed files with 147 additions and 28 deletions
33
ts/util/parseRemoteClientExpiration.ts
Normal file
33
ts/util/parseRemoteClientExpiration.ts
Normal file
|
@ -0,0 +1,33 @@
|
|||
import semver from 'semver';
|
||||
|
||||
type RemoteVersion = {
|
||||
'min-version': string;
|
||||
iso8601: string;
|
||||
};
|
||||
|
||||
export function parseRemoteClientExpiration(
|
||||
remoteExpirationValue: string
|
||||
): number | null {
|
||||
const remoteVersions = JSON.parse(remoteExpirationValue) || [];
|
||||
const ourVersion = window.getVersion();
|
||||
|
||||
return remoteVersions.reduce(
|
||||
(acc: number | null, remoteVersion: RemoteVersion) => {
|
||||
const minVersion = remoteVersion['min-version'];
|
||||
const { iso8601 } = remoteVersion;
|
||||
|
||||
if (semver.gt(minVersion, ourVersion)) {
|
||||
const timestamp = new Date(iso8601).getTime();
|
||||
|
||||
if (!acc) {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
return timestamp < acc ? timestamp : acc;
|
||||
}
|
||||
|
||||
return acc;
|
||||
},
|
||||
null
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue