feat: add license info in getAutomatischInfo query (#1202)

This commit is contained in:
Ömer Faruk Aydın
2023-08-10 23:18:10 +02:00
committed by GitHub
parent ec42446daa
commit 84b701747f
4 changed files with 31 additions and 8 deletions

View File

@@ -0,0 +1,38 @@
// TODO: replace with axios-with-proxy
import axios from 'axios';
import appConfig from '../config/app';
import memoryCache from 'memory-cache';
const CACHE_DURATION = 1000 * 60 * 60 * 24; // 24 hours in milliseconds
const hasValidLicense = async () => {
const license = await getLicense();
return license ? true : false;
};
const getLicense = async () => {
const licenseKey = appConfig.licenseKey;
if (!licenseKey) {
return false;
}
const url = 'https://license.automatisch.io/api/v1/licenses/verify';
const cachedResponse = memoryCache.get(url);
if (cachedResponse) {
return cachedResponse;
} else {
try {
const { data } = await axios.post(url, { licenseKey });
memoryCache.put(url, data, CACHE_DURATION);
return data;
} catch (error) {
return false;
}
}
};
export { getLicense, hasValidLicense };