fix mcp and admin api
This commit is contained in:
@@ -21,6 +21,7 @@ const versionManager = require('./src/utils/versionManager');
|
||||
const { DATA_ROOT, STATE_DIR, DB_PATH, KEY_FILE } = require('./src/database/config');
|
||||
const { initDatabase, getDatabase, closeDatabase } = require('./src/database/connection');
|
||||
const { initEncryption, encrypt, decrypt, isEncryptionInitialized } = require('./src/utils/encryption');
|
||||
const { createExternalAdminApiIntegration } = require('./src/external-admin-api/integration');
|
||||
|
||||
let sharp = null;
|
||||
try {
|
||||
@@ -354,6 +355,9 @@ const AFFILIATE_REF_COOKIE_TTL_SECONDS = Math.floor(AFFILIATE_REF_COOKIE_TTL_MS
|
||||
const ADMIN_USER = process.env.ADMIN_USER || process.env.ADMIN_EMAIL || '';
|
||||
const ADMIN_PASSWORD = process.env.ADMIN_PASSWORD || process.env.ADMIN_PASS || '';
|
||||
const ADMIN_SESSION_TTL_MS = Number(process.env.ADMIN_SESSION_TTL_MS || 86_400_000); // default 24h
|
||||
const ADMIN_API_KEY = process.env.ADMIN_API_KEY || '';
|
||||
const ADMIN_API_JWT_TTL = Number(process.env.ADMIN_API_JWT_TTL || 3600);
|
||||
const ADMIN_API_RATE_LIMIT = Number(process.env.ADMIN_API_RATE_LIMIT || 1000);
|
||||
const ADMIN_MODELS_FILE = path.join(STATE_DIR, 'admin-models.json');
|
||||
const OPENROUTER_SETTINGS_FILE = path.join(STATE_DIR, 'openrouter-settings.json');
|
||||
const MISTRAL_SETTINGS_FILE = path.join(STATE_DIR, 'mistral-settings.json');
|
||||
@@ -1692,6 +1696,9 @@ const RATE_LIMIT_WINDOW_MS = 60000; // 1 minute window
|
||||
// Admin password hashing
|
||||
let adminPasswordHash = null;
|
||||
|
||||
// External Admin API
|
||||
let externalAdminApiRouter = null;
|
||||
|
||||
function log(message, extra) {
|
||||
const payload = extra ? `${message} ${JSON.stringify(extra)}` : message;
|
||||
console.log(`[${new Date().toISOString()}] ${payload}`);
|
||||
@@ -19866,6 +19873,13 @@ async function route(req, res) {
|
||||
|
||||
async function routeInternal(req, res, url, pathname) {
|
||||
if (req.method === 'GET' && pathname === '/api/health') return sendJson(res, 200, { ok: true });
|
||||
|
||||
// Handle External Admin API routes
|
||||
if (pathname.startsWith('/api/external/') && externalAdminApiRouter) {
|
||||
const handled = await externalAdminApiRouter.handle(req, res);
|
||||
if (handled) return;
|
||||
}
|
||||
|
||||
if (req.method === 'GET' && pathname === '/api/opencode/status') return handleOpencodeStatus(req, res);
|
||||
if (req.method === 'GET' && pathname === '/api/memory/stats') return handleMemoryStats(req, res);
|
||||
if (req.method === 'POST' && pathname === '/api/memory/cleanup') return handleForceMemoryCleanup(req, res);
|
||||
@@ -20493,6 +20507,41 @@ async function bootstrap() {
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize External Admin API
|
||||
if (ADMIN_API_KEY) {
|
||||
try {
|
||||
const integration = createExternalAdminApiIntegration({
|
||||
userRepository: null,
|
||||
sessionRepository: null,
|
||||
auditRepository: null,
|
||||
adminModels,
|
||||
publicModels,
|
||||
affiliateAccounts,
|
||||
withdrawals: withdrawalsDb,
|
||||
featureRequests: featureRequestsDb,
|
||||
contactMessages: contactMessagesDb,
|
||||
blogs: blogsDb,
|
||||
trackingStats: trackingData,
|
||||
resourceMonitor: null,
|
||||
tokenUsage: null,
|
||||
log,
|
||||
getConfiguredModels,
|
||||
persistAdminModels,
|
||||
getPlanTokens,
|
||||
getTokenRates,
|
||||
getProviderLimits,
|
||||
getDatabase,
|
||||
databaseEnabled
|
||||
});
|
||||
externalAdminApiRouter = integration.router;
|
||||
log('External Admin API initialized', { configured: integration.isConfigured });
|
||||
} catch (error) {
|
||||
log('Failed to initialize External Admin API', { error: String(error) });
|
||||
}
|
||||
} else {
|
||||
log('External Admin API disabled (ADMIN_API_KEY not set)');
|
||||
}
|
||||
|
||||
log('Resource limits detected', {
|
||||
memoryBytes: RESOURCE_LIMITS.memoryBytes,
|
||||
memoryMb: Math.round((RESOURCE_LIMITS.memoryBytes || 0) / (1024 * 1024)),
|
||||
|
||||
Reference in New Issue
Block a user