66 lines
1.9 KiB
JavaScript
66 lines
1.9 KiB
JavaScript
'use strict';
|
|
|
|
const database = require('../src/core/database');
|
|
const backup = require('../src/core/backup');
|
|
|
|
function parseRecentBatch(raw) {
|
|
try {
|
|
const parsed = JSON.parse(String(raw || ''));
|
|
if (!parsed || !Array.isArray(parsed.emails)) return null;
|
|
return {
|
|
taskId: parsed.taskId || null,
|
|
taskType: parsed.taskType || null,
|
|
emails: [...new Set(parsed.emails.map(email => String(email || '').trim()).filter(Boolean))],
|
|
};
|
|
} catch (_) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function main() {
|
|
database.initDB();
|
|
const batch = parseRecentBatch(database.getSetting('recent_task_batch', ''));
|
|
if (!batch || batch.taskType !== 'custom_pipeline' || batch.emails.length === 0) {
|
|
throw new Error('最近任务不是可恢复的组合任务批次');
|
|
}
|
|
|
|
const db = database.getDb();
|
|
const placeholders = batch.emails.map(() => '?').join(',');
|
|
const restrictedRows = db.prepare(`
|
|
SELECT email FROM accounts
|
|
WHERE restriction_status = 'restricted' AND email IN (${placeholders})
|
|
`).all(...batch.emails);
|
|
|
|
const backupName = backup.createBackupSync('pre_gcp_recovery');
|
|
if (!backupName) throw new Error('恢复前数据库备份失败');
|
|
|
|
const update = db.prepare(`
|
|
UPDATE accounts
|
|
SET ag_status = 'GCP被限制',
|
|
status_reason = 'GCP_RESTRICTED',
|
|
message = '🚫 GCP被限制(已从最近组合任务结果恢复)',
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE email = ? AND restriction_status = 'restricted'
|
|
`);
|
|
const recover = db.transaction((rows) => {
|
|
let changed = 0;
|
|
for (const row of rows) changed += update.run(row.email).changes;
|
|
return changed;
|
|
});
|
|
const changed = recover(restrictedRows);
|
|
|
|
console.log(JSON.stringify({
|
|
taskId: batch.taskId,
|
|
batchAccounts: batch.emails.length,
|
|
restrictedFound: restrictedRows.length,
|
|
changed,
|
|
backupName,
|
|
}, null, 2));
|
|
}
|
|
|
|
try {
|
|
main();
|
|
} finally {
|
|
try { database.getDb().close(); } catch (_) {}
|
|
}
|