fix: implement robust multi-timestamp synchronization logic to prevent data regression
This commit is contained in:
@@ -215,10 +215,10 @@ const scrapeAccountData = async (account: Account) => {
|
||||
account.authError = false; account.lastScrapeTime = now.toISOString();
|
||||
if (result.isActive) {
|
||||
account.cooldownExpiresAt = result.expiresAt ? result.expiresAt.toISOString() : new Date(Date.now() + 86400000).toISOString();
|
||||
if (backend) await backend.pushCooldown(account.steamId, account.cooldownExpiresAt);
|
||||
if (backend) await backend.pushCooldown(account.steamId, account.cooldownExpiresAt, now.toISOString());
|
||||
} else {
|
||||
account.cooldownExpiresAt = undefined;
|
||||
if (backend) await backend.pushCooldown(account.steamId, undefined);
|
||||
if (backend) await backend.pushCooldown(account.steamId, undefined, now.toISOString());
|
||||
}
|
||||
} catch (e: any) {
|
||||
if (e.message.includes('cookie') || e.message.includes('Sign In')) account.authError = true;
|
||||
@@ -267,10 +267,29 @@ const syncAccounts = async (isManual = false) => {
|
||||
exists.sessionUpdatedAt = s.sessionUpdatedAt;
|
||||
hasChanges = true;
|
||||
}
|
||||
if (s.cooldownExpiresAt && (!exists.cooldownExpiresAt || new Date(s.cooldownExpiresAt) > new Date(exists.cooldownExpiresAt))) {
|
||||
exists.cooldownExpiresAt = s.cooldownExpiresAt;
|
||||
|
||||
// Metadata Sync (Pull)
|
||||
const sMetaDate = s.lastMetadataCheck ? new Date(s.lastMetadataCheck) : new Date(0);
|
||||
const lMetaDate = exists.lastBanCheck ? new Date(exists.lastBanCheck) : new Date(0);
|
||||
if (sMetaDate > lMetaDate) {
|
||||
exists.personaName = s.personaName;
|
||||
exists.avatar = s.avatar;
|
||||
exists.vacBanned = s.vacBanned;
|
||||
exists.gameBans = s.gameBans;
|
||||
exists.status = (s.vacBanned || s.gameBans > 0) ? 'banned' : 'none';
|
||||
exists.lastBanCheck = s.lastMetadataCheck;
|
||||
hasChanges = true;
|
||||
}
|
||||
|
||||
// Cooldown Sync (Pull)
|
||||
const sScrapeDate = s.lastScrapeTime ? new Date(s.lastScrapeTime) : new Date(0);
|
||||
const lScrapeDate = exists.lastScrapeTime ? new Date(exists.lastScrapeTime) : new Date(0);
|
||||
if (sScrapeDate > lScrapeDate) {
|
||||
exists.cooldownExpiresAt = s.cooldownExpiresAt;
|
||||
exists.lastScrapeTime = s.lastScrapeTime;
|
||||
hasChanges = true;
|
||||
}
|
||||
|
||||
if (JSON.stringify(exists.sharedWith) !== JSON.stringify(s.sharedWith)) {
|
||||
exists.sharedWith = s.sharedWith;
|
||||
hasChanges = true;
|
||||
|
||||
Reference in New Issue
Block a user