# 后端 API ## 概述 DeEarthX-CE 的后端模块使用 TypeScript 开发,提供了核心功能和 API 接口。本章节将详细介绍后端模块的 API 接口。 ## 模块结构 后端模块包含以下主要目录: - `dearth/` - 核心功能模块 - `modloader/` - 模组加载器相关功能 - `platform/` - 平台集成模块 - `template/` - 模板管理模块 - `utils/` - 工具函数 ## 核心模块 ### dearth/strategies 包含各种模组过滤策略: - `DexpubFilter.ts` - Dexpub 过滤策略 - `HashFilter.ts` - 基于哈希值的过滤策略 - `MixinFilter.ts` - 混合过滤策略 - `ModrinthFilter.ts` - Modrinth 过滤策略 ### dearth/ModCheckService.ts **功能**:负责检查模组的有效性和兼容性 **方法**: - `checkMod(modPath: string): Promise` - **参数**:`modPath` - 模组文件路径 - **返回值**:模组信息对象 - **描述**:检查模组的基本信息和兼容性 - `checkModCompatibility(modInfo: ModInfo, gameVersion: string, modloader: string): Promise` - **参数**: - `modInfo` - 模组信息对象 - `gameVersion` - 游戏版本 - `modloader` - 模组加载器 - **返回值**:是否兼容 - **描述**:检查模组与指定游戏版本和加载器的兼容性 ### dearth/ModFilterService.ts **功能**:负责根据不同策略过滤模组 **方法**: - `filterMods(mods: ModInfo[], strategy: FilterStrategy): Promise` - **参数**: - `mods` - 模组信息数组 - `strategy` - 过滤策略 - **返回值**:过滤后的模组数组 - **描述**:根据指定策略过滤模组 - `registerFilterStrategy(name: string, strategy: FilterStrategy): void` - **参数**: - `name` - 策略名称 - `strategy` - 过滤策略对象 - **返回值**:无 - **描述**:注册新的过滤策略 ## 模组加载器模块 ### modloader/fabric.ts **功能**:处理 Fabric 模组加载器相关操作 **方法**: - `detectFabricMod(modPath: string): Promise` - **参数**:`modPath` - 模组文件路径 - **返回值**:是否为 Fabric 模组 - **描述**:检测指定文件是否为 Fabric 模组 - `getFabricModInfo(modPath: string): Promise` - **参数**:`modPath` - 模组文件路径 - **返回值**:模组信息对象 - **描述**:获取 Fabric 模组的详细信息 ### modloader/forge.ts **功能**:处理 Forge 模组加载器相关操作 **方法**: - `detectForgeMod(modPath: string): Promise` - **参数**:`modPath` - 模组文件路径 - **返回值**:是否为 Forge 模组 - **描述**:检测指定文件是否为 Forge 模组 - `getForgeModInfo(modPath: string): Promise` - **参数**:`modPath` - 模组文件路径 - **返回值**:模组信息对象 - **描述**:获取 Forge 模组的详细信息 ### modloader/neoforge.ts **功能**:处理 NeoForge 模组加载器相关操作 **方法**: - `detectNeoForgeMod(modPath: string): Promise` - **参数**:`modPath` - 模组文件路径 - **返回值**:是否为 NeoForge 模组 - **描述**:检测指定文件是否为 NeoForge 模组 - `getNeoForgeModInfo(modPath: string): Promise` - **参数**:`modPath` - 模组文件路径 - **返回值**:模组信息对象 - **描述**:获取 NeoForge 模组的详细信息 ## 平台集成模块 ### platform/curseforge.ts **功能**:与 CurseForge API 交互 **方法**: - `searchMods(query: string, gameVersion: string): Promise` - **参数**: - `query` - 搜索关键词 - `gameVersion` - 游戏版本 - **返回值**:搜索结果数组 - **描述**:在 CurseForge 上搜索模组 - `getModDetails(modId: string): Promise` - **参数**:`modId` - 模组ID - **返回值**:模组详细信息 - **描述**:获取模组的详细信息 - `downloadMod(modId: string, fileId: string, destination: string): Promise` - **参数**: - `modId` - 模组ID - `fileId` - 文件ID - `destination` - 下载目标路径 - **返回值**:是否下载成功 - **描述**:下载指定模组文件 ### platform/modrinth.ts **功能**:与 Modrinth API 交互 **方法**: - `searchMods(query: string, gameVersion: string): Promise` - **参数**: - `query` - 搜索关键词 - `gameVersion` - 游戏版本 - **返回值**:搜索结果数组 - **描述**:在 Modrinth 上搜索模组 - `getModDetails(modId: string): Promise` - **参数**:`modId` - 模组ID - **返回值**:模组详细信息 - **描述**:获取模组的详细信息 - `downloadMod(modId: string, versionId: string, destination: string): Promise` - **参数**: - `modId` - 模组ID - `versionId` - 版本ID - `destination` - 下载目标路径 - **返回值**:是否下载成功 - **描述**:下载指定模组文件 ## 模板管理模块 ### template/TemplateManager.ts **功能**:负责模板的创建、管理和应用 **方法**: - `createTemplate(name: string, description: string, mods: ModInfo[]): Promise