fix: improve reservation cleanup and share popup handling
This commit is contained in:
@@ -2284,8 +2284,12 @@ const DownloadTrafficReservationDB = {
|
||||
};
|
||||
},
|
||||
|
||||
cleanupFinalizedHistory(keepDays = 7) {
|
||||
const days = Math.min(365, Math.max(1, Math.floor(Number(keepDays) || 7)));
|
||||
cleanupFinalizedHistory(keepDays = 0) {
|
||||
// keepDays=0 表示立即清理全部已完成历史(confirmed/expired/cancelled)
|
||||
const normalized = Number(keepDays);
|
||||
const days = Number.isFinite(normalized)
|
||||
? Math.min(365, Math.max(0, Math.floor(normalized)))
|
||||
: 0;
|
||||
return db.prepare(`
|
||||
DELETE FROM user_download_traffic_reservations
|
||||
WHERE status IN ('confirmed', 'expired', 'cancelled')
|
||||
|
||||
@@ -8843,7 +8843,10 @@ app.post('/api/admin/download-reservations/:id/cancel', authMiddleware, adminMid
|
||||
// 下载流量预扣运维面板:批量清理(过期 pending + 历史 finalized)
|
||||
app.post('/api/admin/download-reservations/cleanup', authMiddleware, adminMiddleware, (req, res) => {
|
||||
try {
|
||||
const keepDays = Math.min(365, Math.max(1, parseInt(req.body?.keep_days, 10) || 7));
|
||||
// 默认 keep_days=0:立即清理全部已完成历史记录,避免“清理无效果”的感知
|
||||
const rawKeepDays = req.body?.keep_days;
|
||||
const parsedKeepDays = Number.isFinite(Number(rawKeepDays)) ? parseInt(rawKeepDays, 10) : 0;
|
||||
const keepDays = Math.min(365, Math.max(0, Number.isFinite(parsedKeepDays) ? parsedKeepDays : 0));
|
||||
const expireResult = DownloadTrafficReservationDB.expirePendingReservations();
|
||||
const cleanupResult = DownloadTrafficReservationDB.cleanupFinalizedHistory(keepDays);
|
||||
|
||||
@@ -8860,7 +8863,7 @@ app.post('/api/admin/download-reservations/cleanup', authMiddleware, adminMiddle
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
message: '预扣清理完成',
|
||||
message: `预扣清理完成(过期待确认 ${Number(expireResult?.changes || 0)} 条,删除历史 ${Number(cleanupResult?.changes || 0)} 条)`,
|
||||
result: {
|
||||
keep_days: keepDays,
|
||||
expired_pending: Number(expireResult?.changes || 0),
|
||||
|
||||
Reference in New Issue
Block a user