diff --git a/backend/database.js b/backend/database.js index 10c88b0..590f354 100644 --- a/backend/database.js +++ b/backend/database.js @@ -303,9 +303,15 @@ const ShareDB = { if (expiry_days) { const expireDate = new Date(); expireDate.setDate(expireDate.getDate() + parseInt(expiry_days)); - // 转换为SQLite datetime格式 (YYYY-MM-DD HH:MM:SS),而不是ISO格式 - // 这样才能正确与 datetime('now') 进行比较 - expiresAt = expireDate.toISOString().replace('T', ' ').replace(/\.\d+Z$/, ''); + // 使用本地时区时间,而不是UTC时间 + // 这样前端解析时会正确显示为本地时间 + const year = expireDate.getFullYear(); + const month = String(expireDate.getMonth() + 1).padStart(2, '0'); + const day = String(expireDate.getDate()).padStart(2, '0'); + const hours = String(expireDate.getHours()).padStart(2, '0'); + const minutes = String(expireDate.getMinutes()).padStart(2, '0'); + const seconds = String(expireDate.getSeconds()).padStart(2, '0'); + expiresAt = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; } const stmt = db.prepare(` @@ -336,7 +342,7 @@ const ShareDB = { // 根据分享码查找 findByCode(shareCode) { // 调试日志: findByCode 调用 - const currentTime = db.prepare("SELECT datetime('now') as now").get(); + const currentTime = db.prepare("SELECT datetime('now', 'localtime') as now").get(); console.log('[ShareDB.findByCode]', { shareCode, currentTime: currentTime.now, @@ -348,7 +354,7 @@ const ShareDB = { FROM shares s JOIN users u ON s.user_id = u.id WHERE s.share_code = ? - AND (s.expires_at IS NULL OR s.expires_at > datetime('now')) + AND (s.expires_at IS NULL OR s.expires_at > datetime('now', 'localtime')) `).get(shareCode); // 调试日志: SQL查询结果