28 lines
1.3 KiB
JavaScript
28 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
const path = require('path');
|
|
const Database = require('better-sqlite3');
|
|
|
|
const backupNames = process.argv.slice(2);
|
|
if (backupNames.length === 0) throw new Error('请提供至少一个备份文件名');
|
|
|
|
for (const name of backupNames) {
|
|
const filePath = path.join(process.cwd(), 'data', 'backups', path.basename(name));
|
|
const db = new Database(filePath, { readonly: true, fileMustExist: true });
|
|
try {
|
|
const total = db.prepare('SELECT COUNT(*) AS count FROM accounts').get().count;
|
|
const active = db.prepare('SELECT COUNT(*) AS count FROM accounts WHERE COALESCE(is_staged, 0) = 0').get().count;
|
|
const restricted = db.prepare("SELECT COUNT(*) AS count FROM accounts WHERE restriction_status = 'restricted'").get().count;
|
|
const activeRestricted = db.prepare(`
|
|
SELECT COUNT(*) AS count FROM accounts
|
|
WHERE restriction_status = 'restricted' AND COALESCE(is_staged, 0) = 0
|
|
`).get().count;
|
|
const recentRaw = db.prepare("SELECT value FROM settings WHERE key = 'recent_task_batch'").get();
|
|
let recentCount = 0;
|
|
try { recentCount = JSON.parse(recentRaw && recentRaw.value || '{}').emails.length || 0; } catch (_) {}
|
|
console.log(JSON.stringify({ name, total, active, restricted, activeRestricted, recentCount }));
|
|
} finally {
|
|
db.close();
|
|
}
|
|
}
|