diff --git a/utils/storage.js b/utils/storage.js index 7f5a401..358bfcd 100644 --- a/utils/storage.js +++ b/utils/storage.js @@ -49,6 +49,18 @@ const getRecords = () => { const saveRecord = (record) => { record.id = String(Date.now()) + '_' + (++_idSeq) + + // Defensive: reject records with a future date. Indicates the user has + // changed their phone clock, which would otherwise poison the cloud + // leaderboard (and their own stats) with impossible timestamps. Allow + // a 1-minute tolerance for normal clock skew. + const recordTime = new Date(record.date.replace(/-/g, '/')).getTime() + if (recordTime > Date.now() + 60 * 1000) { + console.warn('[storage] saveRecord rejected: future date', record.date) + wx.showToast({ title: '系统时间异常,请检查', icon: 'none' }) + return + } + const records = getRecords() const month = record.date.substring(0, 7) if (!records[month]) records[month] = []