UNPKG

mira-app-server

Version:

Mira Server - standalone server application using mira-app-core

86 lines 3.85 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.MiraServer = void 0; const HttpServer_1 = require("./HttpServer"); const LibraryStorage_1 = require("./LibraryStorage"); const server_1 = require("./server"); const SettingsManager_1 = require("./SettingsManager"); const ThumbnailService_1 = require("./services/ThumbnailService"); const MetadataService_1 = require("./services/MetadataService"); const path_1 = __importDefault(require("path")); const DatabaseBackupService_1 = require("./services/DatabaseBackupService"); const DownloadExecutorService_1 = require("./services/DownloadExecutorService"); class MiraServer { constructor(config = {}) { this.config = { httpPort: 8081, wsPort: 8018, ...config }; console.log('🚀 Initializing Mira Server...'); console.log('📋 Configuration:', this.config); this.dataPath = config.dataPath || process.env.DATA_PATH || path_1.default.join(process.cwd(), 'data'); console.log('📂 Data path resolved to:', this.dataPath); } async start() { try { // 初始化设置管理器 this.settingsManager = new SettingsManager_1.SettingsManager(this.dataPath); await this.settingsManager.initialize(); // 初始化缩略图服务 this.thumbnailService = new ThumbnailService_1.ThumbnailService(); this.metadataService = new MetadataService_1.MetadataService(); // 启动HTTP服务器 this.httpServer = new HttpServer_1.MiraHttpServer(this, this.config.dataPath); await this.httpServer.initialize(); await this.httpServer.start(this.config.httpPort); // 启动WebSocket服务器(复用HTTP服务器) this.webSocketServer = new server_1.MiraWebsocketServer(this); await this.webSocketServer.start(this.config.wsPort); console.log(`🔌 WebSocket Server initialized on port ${this.config.wsPort}`); // 缩略图服务接入 WebSocket 广播 this.thumbnailService.setWebSocketServer(this.webSocketServer); console.log('📚 Auto-loading libraries...'); this.libraries = new LibraryStorage_1.LibraryStorage(this); this.libraries.loadAll().then((loaded) => console.log(`✅ ${loaded} Libraries loaded`)); this.databaseBackupService = new DatabaseBackupService_1.DatabaseBackupService(this.dataPath); await this.databaseBackupService.start(); // 下载执行器(消费 cookie 站点下载图片并入库) this.downloadExecutor = new DownloadExecutorService_1.DownloadExecutorService(this); console.log('✅ Mira Server started successfully!'); } catch (error) { console.error('❌ Failed to start Mira Server:', error); throw error; } } async stop() { console.log('🔄 Stopping Mira Server...'); this.databaseBackupService?.stop(); this.metadataService?.clear(); if (this.httpServer) { await this.httpServer.stop(); } console.log('✅ Mira Server stopped successfully'); } getHttpServer() { return this.httpServer; } getDataPath() { return this.dataPath; } getWebSocketServer() { return this.webSocketServer; } // 静态方法用于快速启动 static async createAndStart(config = {}) { const server = new MiraServer(config); await server.start(); return server; } } exports.MiraServer = MiraServer; //# sourceMappingURL=MiraServer.js.map