fix: 修复分享过期时间格式导致的过滤失败问题

## 问题分析
通过调试日志发现,过期分享仍能访问的根本原因是:
- expires_at 存储格式: `2025-11-14T07:31:31.922Z` (ISO 8601)
- datetime('now') 返回格式: `2025-11-14 08:19:52` (SQLite格式)
- SQLite进行字符串比较时: 'T' (ASCII 84) > ' ' (ASCII 32)
- 导致条件 `expires_at > datetime('now')` 对已过期分享仍返回true

## 修复内容
1. database.js: 修改create方法,将expires_at转换为SQLite datetime格式
   - 旧格式: 2025-11-14T07:31:31.922Z
   - 新格式: 2025-11-14 07:31:31

2. fix_expires_at_format.js: 数据库修复脚本
   - 将已存在的ISO格式时间转换为SQLite格式
   - 确保历史数据也能正确过滤

## 部署步骤
```bash
cd /var/www/wanwanyun
git pull
cd backend
node fix_expires_at_format.js  # 修复历史数据
pm2 restart wanwanyun-backend   # 重启服务
```

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-14 16:25:31 +08:00
parent eaf9ad7bb1
commit d56388dd29
2 changed files with 37 additions and 1 deletions

View File

@@ -303,7 +303,9 @@ const ShareDB = {
if (expiry_days) {
const expireDate = new Date();
expireDate.setDate(expireDate.getDate() + parseInt(expiry_days));
expiresAt = expireDate.toISOString();
// 转换为SQLite datetime格式 (YYYY-MM-DD HH:MM:SS),而不是ISO格式
// 这样才能正确与 datetime('now') 进行比较
expiresAt = expireDate.toISOString().replace('T', ' ').replace(/\.\d+Z$/, '');
}
const stmt = db.prepare(`