const fs = require('fs');

const file = 'src/app.ts';
let content = fs.readFileSync(file, 'utf8');

// 1. 修复重复导入
content = content.replace(/import \{ initBookGenerationQueue \} from.*\n/g, '');
content = content.replace(
  "import { queueService } from './services/queue.service';",
  "import { queueService } from './services/queue.service';\nimport { initBookGenerationQueue, resumeInterruptedTasks } from './modules/book-generator/book-queue.processor';"
);

// 2. 添加恢复调用
content = content.replace(
  /initBookGenerationQueue\(\);/,
  `initBookGenerationQueue();
    
    // 自动恢复中断的任务
    resumeInterruptedTasks();`
);

fs.writeFileSync(file, 'utf8', content);
console.log('✅ 已添加自动恢复功能');
