From 73491f4f2c8de048734e3160038b09d07a2f7a2a Mon Sep 17 00:00:00 2001 From: ci010 Date: Wed, 20 Mar 2024 07:26:30 -0700 Subject: [PATCH] fix: Improve the libraries download perf by matching host in accure --- xmcl | 2 +- xmcl-runtime/install/InstallService.ts | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/xmcl b/xmcl index 69995bc4d..e7303a155 160000 --- a/xmcl +++ b/xmcl @@ -1 +1 @@ -Subproject commit 69995bc4dd5c8fadaaf6730d1c15133bedcab2a0 +Subproject commit e7303a15566614dac3fbdb1ed9116cb798fec0f2 diff --git a/xmcl-runtime/install/InstallService.ts b/xmcl-runtime/install/InstallService.ts index b8173588d..83d1281ce 100644 --- a/xmcl-runtime/install/InstallService.ts +++ b/xmcl-runtime/install/InstallService.ts @@ -15,6 +15,7 @@ import { ResourceService } from '~/resource' import { AbstractService, ExposeServiceKey, Lock, Singleton } from '~/service' import { getApiSets, kSettings, shouldOverrideApiSet } from '~/settings' import { TaskFn, kTaskExecutor } from '~/task' +import { joinUrl } from '~/util/url' import { VersionService } from '~/version' import { AnyError } from '../util/error' import { missing } from '../util/fs' @@ -74,7 +75,29 @@ export class InstallService extends AbstractService implements IInstallService { } option.assetsHost = allSets.map(api => api.url ? `${api.url}/assets` : DEFAULT_RESOURCE_ROOT_URL) - option.mavenHost = allSets.map(api => api.url ? `${api.url}/maven` : DEFAULT_FORGE_MAVEN) + option.libraryHost = (lib) => { + const urls = allSets.map(api => { + if (api.url) { + return joinUrl(`${api.url}/maven`, lib.download.path) + } + return lib.download.url + }) + if (lib.name.includes('forge')) { + urls.push(joinUrl(DEFAULT_FORGE_MAVEN, lib.download.path)) + } + const keywords = ['mojang', 'minecraft', 'forge', 'fabric', 'optifine'] + let shouldAppendCommonMaven = true + for (const keyword of keywords) { + if (lib.name.includes(keyword)) { + shouldAppendCommonMaven = false + break + } + } + if (shouldAppendCommonMaven) { + urls.push(joinUrl(DEFAULT_FORGE_MAVEN, lib.download.path)) + } + return urls.map(u => u.replace('/maven/maven', '/maven')) + } option.assetsIndexUrl = (ver) => allSets.map(api => { if (ver.assetIndex) { if (api.name === 'mojang') {