mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-02 12:19:35 +00:00
fix(dashboard): support unified config in overview and file watcher
- overview-routes: Use ProfileRegistry for account count, merge both legacy and unified sources - file-watcher: Add config.yaml to watch list for real-time updates in unified mode Related to #203
This commit is contained in:
@@ -22,7 +22,8 @@ export function createFileWatcher(onChange: FileChangeCallback): FSWatcher {
|
|||||||
|
|
||||||
const watcher = chokidar.watch(
|
const watcher = chokidar.watch(
|
||||||
[
|
[
|
||||||
path.join(ccsDir, 'config.json'),
|
path.join(ccsDir, 'config.json'), // Legacy config
|
||||||
|
path.join(ccsDir, 'config.yaml'), // Unified config
|
||||||
path.join(ccsDir, '*.settings.json'),
|
path.join(ccsDir, '*.settings.json'),
|
||||||
path.join(ccsDir, 'profiles.json'),
|
path.join(ccsDir, 'profiles.json'),
|
||||||
path.join(ccsDir, 'cliproxy', 'sessions.json'), // Proxy session tracking
|
path.join(ccsDir, 'cliproxy', 'sessions.json'), // Proxy session tracking
|
||||||
@@ -41,7 +42,7 @@ export function createFileWatcher(onChange: FileChangeCallback): FSWatcher {
|
|||||||
const basename = path.basename(filePath);
|
const basename = path.basename(filePath);
|
||||||
let type: FileChangeEvent['type'];
|
let type: FileChangeEvent['type'];
|
||||||
|
|
||||||
if (basename === 'config.json') {
|
if (basename === 'config.json' || basename === 'config.yaml') {
|
||||||
type = 'config-changed';
|
type = 'config-changed';
|
||||||
} else if (basename === 'profiles.json') {
|
} else if (basename === 'profiles.json') {
|
||||||
type = 'profiles-changed';
|
type = 'profiles-changed';
|
||||||
|
|||||||
@@ -5,12 +5,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Router, Request, Response } from 'express';
|
import { Router, Request, Response } from 'express';
|
||||||
import * as fs from 'fs';
|
import { loadConfig } from '../utils/config-manager';
|
||||||
import * as path from 'path';
|
|
||||||
import { getCcsDir, loadConfig } from '../utils/config-manager';
|
|
||||||
import { runHealthChecks } from './health-service';
|
import { runHealthChecks } from './health-service';
|
||||||
import { getAllAuthStatus, initializeAccounts } from '../cliproxy/auth-handler';
|
import { getAllAuthStatus, initializeAccounts } from '../cliproxy/auth-handler';
|
||||||
import { getVersion } from '../utils/version';
|
import { getVersion } from '../utils/version';
|
||||||
|
import ProfileRegistry from '../auth/profile-registry';
|
||||||
|
|
||||||
export const overviewRoutes = Router();
|
export const overviewRoutes = Router();
|
||||||
|
|
||||||
@@ -64,12 +63,16 @@ overviewRoutes.get('/', async (_req: Request, res: Response) => {
|
|||||||
|
|
||||||
function getAccountCount(): number {
|
function getAccountCount(): number {
|
||||||
try {
|
try {
|
||||||
const profilesPath = path.join(getCcsDir(), 'profiles.json');
|
const registry = new ProfileRegistry();
|
||||||
|
|
||||||
if (!fs.existsSync(profilesPath)) return 0;
|
// Merge legacy (profiles.json) and unified (config.yaml) accounts
|
||||||
|
const legacyProfiles = registry.getAllProfiles();
|
||||||
|
const unifiedAccounts = registry.getAllAccountsUnified();
|
||||||
|
|
||||||
const data = JSON.parse(fs.readFileSync(profilesPath, 'utf8'));
|
// Count unique accounts (unified takes precedence for duplicates)
|
||||||
return Object.keys(data.profiles || {}).length;
|
const allNames = new Set([...Object.keys(legacyProfiles), ...Object.keys(unifiedAccounts)]);
|
||||||
|
|
||||||
|
return allNames.size;
|
||||||
} catch {
|
} catch {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user