v.1.0.0. initial push of license-lib
This commit is contained in:
24
client/offline.js
Normal file
24
client/offline.js
Normal file
@@ -0,0 +1,24 @@
|
||||
// client/offline.js
|
||||
|
||||
const CACHE_KEY = 'license_data';
|
||||
|
||||
export const cacheLicenseData = (licenseData) => {
|
||||
localStorage.setItem(CACHE_KEY, JSON.stringify({
|
||||
data: licenseData,
|
||||
cachedAt: Date.now(),
|
||||
}));
|
||||
};
|
||||
|
||||
export const getCachedLicenseData = () => {
|
||||
const item = localStorage.getItem(CACHE_KEY);
|
||||
return item ? JSON.parse(item) : null;
|
||||
};
|
||||
|
||||
export const isLicenseCacheValid = () => {
|
||||
const cache = getCachedLicenseData();
|
||||
if (!cache) return false;
|
||||
|
||||
const cachedAt = cache.cachedAt;
|
||||
const elapsedDays = (Date.now() - cachedAt) / (1000 * 60 * 60 * 24);
|
||||
return elapsedDays <= CONFIG.OFFLINE_GRACE_PERIOD_DAYS;
|
||||
};
|
Reference in New Issue
Block a user