2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-08-23 22:45:11 +00:00
|
|
|
import { Environment, getEnvironment } from '../environment';
|
|
|
|
import { isInPast } from './timestamp';
|
2021-09-17 18:27:53 +00:00
|
|
|
import * as log from '../logging/log';
|
2022-11-22 18:43:43 +00:00
|
|
|
import * as Errors from '../types/errors';
|
2020-02-12 21:30:58 +00:00
|
|
|
|
2021-08-23 22:45:11 +00:00
|
|
|
const ONE_DAY_MS = 86400 * 1000;
|
|
|
|
const NINETY_ONE_DAYS = 91 * ONE_DAY_MS;
|
|
|
|
const THIRTY_ONE_DAYS = 31 * ONE_DAY_MS;
|
2020-02-12 21:30:58 +00:00
|
|
|
|
2020-09-14 21:56:35 +00:00
|
|
|
export function hasExpired(): boolean {
|
2020-02-12 21:30:58 +00:00
|
|
|
let buildExpiration = 0;
|
|
|
|
|
|
|
|
try {
|
2022-06-13 21:39:35 +00:00
|
|
|
buildExpiration = window.getExpiration();
|
2020-02-12 21:30:58 +00:00
|
|
|
if (buildExpiration) {
|
|
|
|
log.info('Build expires: ', new Date(buildExpiration).toISOString());
|
|
|
|
}
|
|
|
|
} catch (e) {
|
2022-11-22 18:43:43 +00:00
|
|
|
log.error('Error retrieving build expiration date', Errors.toLogFormat(e));
|
2020-02-12 21:30:58 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-08-23 22:45:11 +00:00
|
|
|
if (getEnvironment() === Environment.Production) {
|
|
|
|
const safeExpirationMs = window.Events.getAutoDownloadUpdate()
|
|
|
|
? NINETY_ONE_DAYS
|
|
|
|
: THIRTY_ONE_DAYS;
|
2020-02-12 21:30:58 +00:00
|
|
|
|
2021-08-23 22:45:11 +00:00
|
|
|
const buildExpirationDuration = buildExpiration - Date.now();
|
|
|
|
const tooFarIntoFuture = buildExpirationDuration > safeExpirationMs;
|
|
|
|
|
|
|
|
if (tooFarIntoFuture) {
|
|
|
|
log.error(
|
|
|
|
'Build expiration is set too far into the future',
|
|
|
|
buildExpiration
|
|
|
|
);
|
|
|
|
}
|
2020-02-12 21:30:58 +00:00
|
|
|
|
2021-08-23 22:45:11 +00:00
|
|
|
return tooFarIntoFuture || isInPast(buildExpiration);
|
2020-02-12 21:30:58 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 22:45:11 +00:00
|
|
|
return buildExpiration !== 0 && isInPast(buildExpiration);
|
2020-02-12 21:30:58 +00:00
|
|
|
}
|