(
instanceUuid: string,
url: string,
fileName: string,
type: "mod" | "plugin",
options: { fallbackUrl?: string } = {}
)
| 378 | } |
| 379 | |
| 380 | public async installMod( |
| 381 | instanceUuid: string, |
| 382 | url: string, |
| 383 | fileName: string, |
| 384 | type: "mod" | "plugin", |
| 385 | options: { fallbackUrl?: string } = {} |
| 386 | ) { |
| 387 | const instance = InstanceSubsystem.getInstance(instanceUuid)!; |
| 388 | const cwd = instance.absoluteCwdPath(); |
| 389 | const fileManager = new FileManager( |
| 390 | resolveMCDRServerRoot(instance.config.type, cwd) ?? cwd, |
| 391 | instance.config?.fileCode |
| 392 | ); |
| 393 | const rootDir = fileManager.toAbsolutePath("."); |
| 394 | |
| 395 | // Determine the save directory based on what exists (case-sensitive check for Linux) |
| 396 | let saveDir = type === "plugin" ? "plugins" : "mods"; |
| 397 | const variants = type === "plugin" ? ["plugins", "Plugins"] : ["mods", "Mods"]; |
| 398 | |
| 399 | for (const v of variants) { |
| 400 | if (await fs.pathExists(path.join(rootDir, v))) { |
| 401 | saveDir = v; |
| 402 | break; |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | const relativePath = path.join(saveDir, fileName); |
| 407 | if (!fileManager.checkPath(relativePath)) throw new Error("Invalid file path"); |
| 408 | const targetPath = fileManager.toAbsolutePath(relativePath); |
| 409 | |
| 410 | logger.info( |
| 411 | `[ModService] Instance ${instanceUuid} Install Mod: ${fileName} from ${url} to ${targetPath}` |
| 412 | ); |
| 413 | logger.info(`[ModService] Options: ${JSON.stringify(options)}`); |
| 414 | |
| 415 | await downloadManager.downloadFromUrl(url, targetPath, options.fallbackUrl); |
| 416 | } |
| 417 | |
| 418 | public async getModConfig( |
| 419 | instanceUuid: string, |
no test coverage detected