mirror of
https://github.com/RubyMetric/chsrc
synced 2025-10-09 21:33:23 +08:00
Rename doc
This commit is contained in:
63
doc/11-如何设置换源链接与测速链接.md
Normal file
63
doc/11-如何设置换源链接与测速链接.md
Normal file
@@ -0,0 +1,63 @@
|
||||
<!-- -----------------------------------------------------------
|
||||
! SPDX-License-Identifier: GFDL-1.3-or-later
|
||||
! -------------------------------------------------------------
|
||||
! Doc Type : Markdown
|
||||
! Doc Name : 11-如何设置换源链接与测速链接.md
|
||||
! Doc Authors : Aoran Zeng <ccmywish@qq.com>
|
||||
! Contributors : Nul None <nul@none.org>
|
||||
! |
|
||||
! Created On : <2025-08-11>
|
||||
! Last Modified : <2025-08-11>
|
||||
! ---------------------------------------------------------- -->
|
||||
|
||||
# 新增/修改 "换源链接"
|
||||
|
||||
在 `_prelude()` 函数中,在 `def_sources_begin()` 的位置的**第二列**,新增/修改你想要替换的链接。
|
||||
|
||||
**注: 以下代码仅起解释作用,JavaScript换源的真正实现可能不同**
|
||||
|
||||
```c
|
||||
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()
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
|
||||
# 设置/修改 "测速链接"
|
||||
|
||||
在 `_prelude()` 函数中,在 `def_sources_begin()` 的位置的**第三列**,设置/修改你想要替换的链接。
|
||||
|
||||
1. 在下面代码的第一行中,我们直接给了一个链接,**这就是精准测速链接**
|
||||
2. 在下面代码的第二行和第三行中,我们都设置了一个宏 `DelegateToMirror`,这意味着我们没有直接提供精准测速链接,而是让 `chsrc` 去测试其对应镜像站定义的测速链接
|
||||
|
||||
- `NpmMirror` 是专用镜像站,所以其测速链接被设置为了 `ACCURATE`,即精准测速
|
||||
- `Huawei` 是通用镜像站,所以其测速链接被设置为了 `ROUGH `,即模糊测速
|
||||
|
||||
3. 在下面代码的第四行中,我们设置了一个宏 `FeedByPrelude`,这意味着我们将在 `_prelude()` 函数的后续动态计算 URL
|
||||
|
||||
**注: 以下代码仅起解释作用,JavaScript换源的真正实现可能不同**
|
||||
|
||||
```c
|
||||
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);;
|
||||
```
|
Reference in New Issue
Block a user