Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async update(settings) {
logs.add(
`dataSource: ${settings.dataSource} dataSourceTwo: ${settings.dataSourceTwo} PhoneType: ${companion.host.os.name} modelName: ${device.modelName} version: ${config.version} build: ${config.build}`
);
// check to see if there is a token
if (config.firebase_token.length > 0) {
// ----------------------------------------hr---min--sec--ms
let halfADayAgo = Math.floor((Date.now() - 12 * 60 * 60 * 1000) / 1000);
let localStorageUpdatedAt = localStorage.getItem("updatedAt");
// check if they have update their user data within the last half day
if (!localStorageUpdatedAt || localStorageUpdatedAt <= halfADayAgo) {
// get the uuid or create a new one
let didCreateNewUuid = false;
let uuid = null;
if (settingsStorage.getItem("uuid")) {
didCreateNewUuid = false;
uuid = JSON.parse(settingsStorage.getItem("uuid")).name;
} else if (!uuid) {
didCreateNewUuid = true;
// data["buildId"] = me.buildId;
} else {
// old record so we need to get the data first
data = await fetch.get(url);
// if the record doesn't exist
if (!data) {
data = {};
data["createdAt"] = Math.floor(Date.now() / 1000);
}
data["uuid"] = uuid;
data["updatedAt"] = Math.floor(Date.now() / 1000);
data["userAgreement"] = settings.userAgreement;
data["dataSource"] = settings.dataSource;
data["dataSourceTwo"] = settings.dataSourceTwo;
data["phoneType"] = companion.host.os.name;
data["device"] = device.modelName;
data["version"] = config.version;
// data.buildId = me.buildId;
}
localStorage.setItem("updatedAt", data["updatedAt"]);
// update the record
await fetch.put(url, data);
}
}
}
}