47 lines
1.5 KiB
JavaScript
47 lines
1.5 KiB
JavaScript
const { db } = require('./database');
|
|
|
|
console.log('开始修复 expires_at 格式...\n');
|
|
|
|
// 查找所有有过期时间的分享
|
|
const shares = db.prepare(`
|
|
SELECT id, share_code, expires_at
|
|
FROM shares
|
|
WHERE expires_at IS NOT NULL
|
|
`).all();
|
|
|
|
console.log(`找到 ${shares.length} 条需要修复的记录\n`);
|
|
|
|
let fixed = 0;
|
|
const updateStmt = db.prepare('UPDATE shares SET expires_at = ? WHERE id = ?');
|
|
|
|
shares.forEach(share => {
|
|
const oldFormat = share.expires_at;
|
|
|
|
// 如果是ISO格式(包含T和Z),需要转换
|
|
if (oldFormat.includes('T') || oldFormat.includes('Z')) {
|
|
const parsed = new Date(oldFormat);
|
|
if (Number.isNaN(parsed.getTime())) {
|
|
console.warn(`跳过无法解析的时间: ${share.share_code} -> ${oldFormat}`);
|
|
return;
|
|
}
|
|
|
|
// 转换为本地时区 SQLite datetime 格式: YYYY-MM-DD HH:MM:SS
|
|
const year = parsed.getFullYear();
|
|
const month = String(parsed.getMonth() + 1).padStart(2, '0');
|
|
const day = String(parsed.getDate()).padStart(2, '0');
|
|
const hours = String(parsed.getHours()).padStart(2, '0');
|
|
const minutes = String(parsed.getMinutes()).padStart(2, '0');
|
|
const seconds = String(parsed.getSeconds()).padStart(2, '0');
|
|
const newFormat = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
|
|
|
updateStmt.run(newFormat, share.id);
|
|
fixed++;
|
|
|
|
console.log(`✓ 修复分享 ${share.share_code}:`);
|
|
console.log(` 旧格式: ${oldFormat}`);
|
|
console.log(` 新格式: ${newFormat}\n`);
|
|
}
|
|
});
|
|
|
|
console.log(`\n修复完成! 共修复 ${fixed} 条记录`);
|