mirror of
https://github.com/RubyMetric/chsrc
synced 2025-08-13 15:59:32 +08:00
3.1 KiB
3.1 KiB
新增/修改 "换源链接"
在 _prelude()
函数中,在 def_sources_begin()
的位置的第二列,新增/修改你想要替换的链接。
注: 以下代码仅起解释作用,JavaScript换源的真正实现可能不同
def_sources_begin()
{&UpstreamProvider, "https://registry.npmjs.org/", FeedByPrelude},
{&NpmMirror, "https://registry.npmmirror.com", FeedByPrelude},
{&Huawei, "https://mirrors.huaweicloud.com/repository/npm/", FeedByPrelude},
{&Tencent, "https://mirrors.cloud.tencent.com/npm/", FeedByPrelude},
{&某新镜像站, "某镜像站提供的换源链接", FeedByPrelude}
def_sources_end()
设置/修改 "测速链接"
在 _prelude()
函数中,在 def_sources_begin()
的位置的第三列,设置/修改你想要替换的链接。
-
在下面代码的第一行中,我们直接给了一个链接,这就是精准测速链接
-
在下面代码的第二行和第三行中,我们都设置了一个宏
DelegateToMirror
,这意味着我们没有直接提供精准测速链接,而是让chsrc
去测试其对应镜像站定义的测速链接NpmMirror
是专用镜像站,所以其测速链接被设置为了ACCURATE
,即精准测速Huawei
是通用镜像站,所以其测速链接被设置为了ROUGH
,即模糊测速
-
在下面代码的第四行中,我们设置了一个宏
FeedByPrelude
,这意味着我们将在_prelude()
函数的后续动态计算 URL
注: 以下代码仅起解释作用,JavaScript换源的真正实现可能不同
def_sources_begin()
{&UpstreamProvider, "https://registry.npmjs.org/", "https://registry.npmjs.org/BigFile.tar.gz"},
{&NpmMirror, "https://registry.npmmirror.com", DelegateToMirror},
{&Huawei, "https://mirrors.huaweicloud.com/repository/npm/", DelegateToMirror},
{&Tencent, "https://mirrors.cloud.tencent.com/npm/", FeedByPrelude},
def_sources_end()
// 把所有上述源的 "测速链接" 设置为 "换源链接" + postfix
chef_set_sources_speed_measure_url_with_postfix (this, "/dir/BigFile.tar.gz");
// 基于 "换源链接" 做更自定义的操作
chef_set_sources_speed_measure_url_with_func (this, func, data);
// 调整某一个镜像站(Provider)的 "测速链接"
chef_set_provider_speed_measure_url (&Tencent, "https://mirrors.cloud.tencent.com/npm/BigFile.tar.gz")
// 调整某一个镜像站(Provider)的 "测速精度"
chef_set_provider_speed_measure_accuracy (&UpstreamProvider, ROUGH);;