Refactor: delete dead code, extract utils, rename files for clarity
- Delete scheduler-mcp.ts (285 lines of dead code, unused) - Extract loadJson/saveJson to utils.ts (generic utilities) - Rename auth.ts → whatsapp-auth.ts (more specific) - Rename scheduler.ts → task-scheduler.ts (more specific) - Update all references in docs and imports Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
19
src/index.ts
19
src/index.ts
@@ -20,8 +20,9 @@ import {
|
||||
} from './config.js';
|
||||
import { RegisteredGroup, Session, NewMessage } from './types.js';
|
||||
import { initDatabase, storeMessage, storeChatMetadata, getNewMessages, getMessagesSince, getAllTasks, getTaskById } from './db.js';
|
||||
import { startSchedulerLoop } from './scheduler.js';
|
||||
import { startSchedulerLoop } from './task-scheduler.js';
|
||||
import { runContainerAgent, writeTasksSnapshot } from './container-runner.js';
|
||||
import { loadJson, saveJson } from './utils.js';
|
||||
|
||||
const logger = pino({
|
||||
level: process.env.LOG_LEVEL || 'info',
|
||||
@@ -42,22 +43,6 @@ async function setTyping(jid: string, isTyping: boolean): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
function loadJson<T>(filePath: string, defaultValue: T): T {
|
||||
try {
|
||||
if (fs.existsSync(filePath)) {
|
||||
return JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
||||
}
|
||||
} catch (e) {
|
||||
logger.warn({ filePath, error: e }, 'Failed to load JSON file');
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
function saveJson(filePath: string, data: unknown): void {
|
||||
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
||||
fs.writeFileSync(filePath, JSON.stringify(data, null, 2));
|
||||
}
|
||||
|
||||
function loadState(): void {
|
||||
const statePath = path.join(DATA_DIR, 'router_state.json');
|
||||
const state = loadJson<{ last_timestamp?: string; last_agent_timestamp?: Record<string, string> }>(statePath, {});
|
||||
|
||||
Reference in New Issue
Block a user