mirror of
https://github.com/RubyMetric/chsrc
synced 2026-02-02 15:50:29 +08:00
精简 API
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
! Contributors : Nul None <nul@none.org>
|
||||
! |
|
||||
! Created On : <2024-08-19>
|
||||
! Last Modified : <2025-10-28>
|
||||
! Last Modified : <2026-01-21>
|
||||
! ---------------------------------------------------------- -->
|
||||
|
||||
# Write A Recipe Even If You Don't Know C
|
||||
@@ -57,6 +57,11 @@
|
||||
- **换源链接**: 指镜像站所提供的某一个具体的换源使用的URL
|
||||
- **测速链接**: 用来测速的URL,与 "换源链接" 不同,可分为 **精准测速** 和 **模糊测速**
|
||||
|
||||
1. 在代码中,测速链接一般使用 `smurl` (即 `speed measure URL`) 来指代
|
||||
2. 在代码中,换源链接一般使用 `repourl` (即 `repository URL`) 来指代
|
||||
|
||||
为什么不用 `regurl`,因为使用术语 `repository` 的 target 远多于使用术语 `registry` 的。
|
||||
|
||||
- **镜像源**: 为了方便,**偶尔**我们将直接称`mirror`和/或`source`为**镜像源**,这只是一种方便性的称呼,可以统称二者,也可以根据上下文指代二者之一
|
||||
|
||||
<br>
|
||||
|
||||
@@ -28,7 +28,7 @@ def_sources_end()
|
||||
//
|
||||
|
||||
// 调整上述某一个镜像站的所提供源的 "换源链接"
|
||||
chef_set_source_url (this, &UpstreamProvider, "新的换源链接");
|
||||
chef_set_url (this, &UpstreamProvider, "新的换源链接");
|
||||
```
|
||||
|
||||
<br>
|
||||
@@ -59,14 +59,14 @@ def_sources_end()
|
||||
//
|
||||
|
||||
// 调整/设置上述某一个镜像站的所提供源的 "精准测速链接"
|
||||
chef_set_source_smurl (this, &UpstreamProvider, "新的测速链接")
|
||||
chef_set_smurl (this, &UpstreamProvider, "新的测速链接")
|
||||
// 把所有上述源的 "测速链接" 设置为 "换源链接" + postfix
|
||||
chef_set_sources_speed_measure_url_with_postfix (this, "/dir/BigFile.tar.gz");
|
||||
chef_set_all_smurl_with_postfix (this, "/dir/BigFile.tar.gz");
|
||||
// 基于 "换源链接" 做更自定义的操作
|
||||
chef_set_sources_speed_measure_url_with_func (this, func, data);
|
||||
chef_set_all_smurl_with_func (this, func, data);
|
||||
|
||||
// 调整某一个镜像站(Provider)的 "测速链接"
|
||||
chef_set_provider_speed_measure_url (&Tencent, "https://mirrors.cloud.tencent.com/npm/BigFile.tar.gz");
|
||||
chef_set_provider_smurl (&Tencent, "https://mirrors.cloud.tencent.com/npm/BigFile.tar.gz");
|
||||
// 调整某一个镜像站(Provider)的 "测速精度"
|
||||
chef_set_provider_speed_measure_accuracy (&UpstreamProvider, ROUGH);
|
||||
chef_set_provider_sm_accuracy (&UpstreamProvider, ROUGH);
|
||||
```
|
||||
|
||||
@@ -95,7 +95,7 @@ chef_register_contributor (char *id, char *name, char *email, char *display_name
|
||||
* @note 这个修改的是全局 Provider 里的信息。往往用来设置 UpstreamProvider
|
||||
*/
|
||||
void
|
||||
chef_set_provider_speed_measure_url (SourceProvider_t *provider, char *url)
|
||||
chef_set_provider_smurl (SourceProvider_t *provider, char *url)
|
||||
{
|
||||
provider->psmi.skip = NotSkip;
|
||||
provider->psmi.url = xy_strdup (url);
|
||||
@@ -109,18 +109,71 @@ chef_set_provider_speed_measure_url (SourceProvider_t *provider, char *url)
|
||||
* @note 这个修改的是全局 Provider 里的信息。往往用来设置 UpstreamProvider
|
||||
*/
|
||||
void
|
||||
chef_set_provider_speed_measure_accuracy (SourceProvider_t *provider, bool accuracy)
|
||||
chef_set_provider_sm_accuracy (SourceProvider_t *provider, bool accuracy)
|
||||
{
|
||||
provider->psmi.accurate = accuracy;
|
||||
chsrc_debug ("m", xy_strcat (4, "recipe 重新为 ", provider->code, "(镜像站信息本身) 设置测速精度: ", accuracy ? "精准" : "粗略"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 修改 或 补充 某个镜像站的换源链接
|
||||
*
|
||||
* @example 见 os_ubuntu_resetsrc() 中对非 x86_64 架构源地址的修改
|
||||
*/
|
||||
void
|
||||
chef_set_url (Target_t *target, SourceProvider_t *provider, char *url)
|
||||
{
|
||||
xy_cant_be_null (target);
|
||||
xy_cant_be_null (provider);
|
||||
xy_cant_be_null (url);
|
||||
|
||||
for (int i=0; i < target->sources_n; i++)
|
||||
{
|
||||
Source_t *src = &target->sources[i];
|
||||
SourceProvider_t *p = src->provider;
|
||||
if (p == provider)
|
||||
{
|
||||
src->url = xy_strdup (url);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
xy_unreached();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 或 修改 某个镜像站的 *精准*测速链接
|
||||
*
|
||||
* sm = speed measure
|
||||
*/
|
||||
void
|
||||
chef_set_smurl (Target_t *target, SourceProvider_t *provider, char *url)
|
||||
{
|
||||
xy_cant_be_null (target);
|
||||
xy_cant_be_null (provider);
|
||||
xy_cant_be_null (url);
|
||||
|
||||
for (int i=0; i < target->sources_n; i++)
|
||||
{
|
||||
Source_t *src = &target->sources[i];
|
||||
SourceProvider_t *p = src->provider;
|
||||
if (p == provider)
|
||||
{
|
||||
src->speed_measure_url = xy_strdup (url);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
xy_unreached();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 提供一个函数,这个函数基于 "换源链接" 和用户提供的数据来构造和填充精准测速链接
|
||||
*/
|
||||
void
|
||||
chef_set_sources_speed_measure_url_with_func (
|
||||
chef_set_all_smurl_with_func (
|
||||
Target_t *target,
|
||||
char *(*func)(const char *url, const char *user_data),
|
||||
char *user_data)
|
||||
@@ -150,62 +203,9 @@ chef_set_sources_speed_measure_url_with_func (
|
||||
* @brief 给 "换源链接" 增加一个后缀来构造和填充专用测速链接
|
||||
*/
|
||||
void
|
||||
chef_set_sources_speed_measure_url_with_postfix (Target_t *target, char *postfix)
|
||||
chef_set_all_smurl_with_postfix (Target_t *target, char *postfix)
|
||||
{
|
||||
chef_set_sources_speed_measure_url_with_func (target, xy_2strcat, postfix);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 修改 或 补充 某个镜像站的换源链接
|
||||
*
|
||||
* @example 见 os_ubuntu_resetsrc() 中对非 x86_64 架构源地址的修改
|
||||
*/
|
||||
void
|
||||
chef_set_source_url (Target_t *target, SourceProvider_t *provider, char *url)
|
||||
{
|
||||
xy_cant_be_null (target);
|
||||
xy_cant_be_null (provider);
|
||||
xy_cant_be_null (url);
|
||||
|
||||
for (int i=0; i < target->sources_n; i++)
|
||||
{
|
||||
Source_t *src = &target->sources[i];
|
||||
SourceProvider_t *p = src->provider;
|
||||
if (p == provider)
|
||||
{
|
||||
src->url = xy_strdup (url);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
xy_unreached();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 或 修改 某个镜像站的 *精准*测速链接
|
||||
*
|
||||
* sm = speed measure
|
||||
*/
|
||||
void
|
||||
chef_set_source_smurl (Target_t *target, SourceProvider_t *provider, char *url)
|
||||
{
|
||||
xy_cant_be_null (target);
|
||||
xy_cant_be_null (provider);
|
||||
xy_cant_be_null (url);
|
||||
|
||||
for (int i=0; i < target->sources_n; i++)
|
||||
{
|
||||
Source_t *src = &target->sources[i];
|
||||
SourceProvider_t *p = src->provider;
|
||||
if (p == provider)
|
||||
{
|
||||
src->speed_measure_url = xy_strdup (url);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
xy_unreached();
|
||||
chef_set_all_smurl_with_func (target, xy_2strcat, postfix);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -181,9 +181,9 @@ Target_t;
|
||||
* def_sources_end()
|
||||
*
|
||||
* 若是出于代码美观考虑,上述第三列可以写 FeedByPrelude,然后下面调用函数来填充:
|
||||
* chef_set_source_smurl()
|
||||
* chef_set_sources_speed_measure_url_with_postfix()
|
||||
* chef_set_sources_speed_measure_url_with_func()
|
||||
* chef_set_smurl()
|
||||
* chef_set_all_smurl_with_postfix()
|
||||
* chef_set_all_smurl_with_func()
|
||||
*/
|
||||
#define def_sources_begin() Source_t sources[] = {
|
||||
#define def_sources_end() }; \
|
||||
|
||||
@@ -29,7 +29,7 @@ pl_dart_flutter_prelude (void)
|
||||
{&Nju, "https://mirror.nju.edu.cn/flutter", FeedByPrelude}
|
||||
def_sources_end()
|
||||
|
||||
chef_set_sources_speed_measure_url_with_postfix (this, "/flutter_infra_release/releases/stable/linux/flutter_linux_v1.0.0-stable.tar.xz");
|
||||
chef_set_all_smurl_with_postfix (this, "/flutter_infra_release/releases/stable/linux/flutter_linux_v1.0.0-stable.tar.xz");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ pl_dart_prelude (void)
|
||||
{&Nju, "https://mirror.nju.edu.cn/dart-pub", FeedByPrelude}
|
||||
def_sources_end()
|
||||
|
||||
chef_set_sources_speed_measure_url_with_postfix (this, "/packages/flutter_vision/versions/1.1.4.tar.gz");
|
||||
chef_set_all_smurl_with_postfix (this, "/packages/flutter_vision/versions/1.1.4.tar.gz");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ pl_java_prelude ()
|
||||
def_sources_end()
|
||||
|
||||
// 220MB
|
||||
chef_set_sources_speed_measure_url_with_postfix (this, "com/tencentcloudapi/tencentcloud-sdk-java/3.1.1033/tencentcloud-sdk-java-3.1.1033-javadoc.jar");
|
||||
chef_set_all_smurl_with_postfix (this, "com/tencentcloudapi/tencentcloud-sdk-java/3.1.1033/tencentcloud-sdk-java-3.1.1033-javadoc.jar");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ pl_js_group_prelude (void)
|
||||
def_sources_end()
|
||||
|
||||
// 29MB 大小
|
||||
chef_set_sources_speed_measure_url_with_postfix (this, "/@tensorflow/tfjs/-/tfjs-4.22.0.tgz");
|
||||
chef_set_all_smurl_with_postfix (this, "/@tensorflow/tfjs/-/tfjs-4.22.0.tgz");
|
||||
}
|
||||
|
||||
|
||||
@@ -73,5 +73,5 @@ pl_js_nodejs_binary_prelude (void)
|
||||
{&Tencent, "https://mirrors.cloud.tencent.com/nodejs-release/", FeedByPrelude}
|
||||
def_sources_end()
|
||||
|
||||
chef_set_sources_speed_measure_url_with_postfix (this, "/v23.4.0/node-v23.4.0-linux-x64.tar.xz");
|
||||
chef_set_all_smurl_with_postfix (this, "/v23.4.0/node-v23.4.0-linux-x64.tar.xz");
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ pl_perl_prelude ()
|
||||
{&Ali, "https://mirrors.aliyun.com/CPAN/", FeedByPrelude}
|
||||
def_sources_end()
|
||||
|
||||
chef_set_sources_speed_measure_url_with_postfix (this, "authors/id/D/DB/DBAURAIN/Bio-MUST-Apps-FortyTwo-0.213470.tar.gz");
|
||||
chef_set_all_smurl_with_postfix (this, "authors/id/D/DB/DBAURAIN/Bio-MUST-Apps-FortyTwo-0.213470.tar.gz");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ pl_python_group_prelude (void)
|
||||
// {&Netease, "https://mirrors.163.com/.help/pypi.html", NULL}
|
||||
def_sources_end()
|
||||
|
||||
chef_set_sources_speed_measure_url_with_func (this, pl_python_speed_url_constructor, NULL);
|
||||
chef_set_all_smurl_with_func (this, pl_python_speed_url_constructor, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -38,7 +38,7 @@ pl_rust_rustup_prelude (void)
|
||||
def_sources_end()
|
||||
|
||||
// 20MB大小
|
||||
chef_set_sources_speed_measure_url_with_postfix (this, "/dist/2025-06-26/cargo-1.88.0-x86_64-unknown-illumos.tar.gz");
|
||||
chef_set_all_smurl_with_postfix (this, "/dist/2025-06-26/cargo-1.88.0-x86_64-unknown-illumos.tar.gz");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ os_debian_prelude ()
|
||||
// {&Sohu, "https://mirrors.sohu.com/debian", FeedByPrelude}
|
||||
def_sources_end()
|
||||
|
||||
chef_set_sources_speed_measure_url_with_postfix (this, "/dists/bookworm/main/Contents-all.gz");
|
||||
chef_set_all_smurl_with_postfix (this, "/dists/bookworm/main/Contents-all.gz");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ os_ubuntu_prelude ()
|
||||
// {&Sohu, "https://mirrors.sohu.com/ubuntu", FeedByPrelude}
|
||||
def_sources_end()
|
||||
|
||||
chef_set_sources_speed_measure_url_with_postfix (this, "/dists/noble/Contents-amd64.gz");
|
||||
chef_set_all_smurl_with_postfix (this, "/dists/noble/Contents-amd64.gz");
|
||||
}
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@ os_ubuntu_resetsrc (char *option)
|
||||
if (strncmp (arch, "x86_64", 6)!=0)
|
||||
{
|
||||
// Ubuntu 非 x86_64 架构的源地址有所不同
|
||||
chef_set_source_url (this, &UpstreamProvider, "http://ports.ubuntu.com/ubuntu");
|
||||
chef_set_url (this, &UpstreamProvider, "http://ports.ubuntu.com/ubuntu");
|
||||
// this->sources[0].url = "http://ports.ubuntu.com/ubuntu";
|
||||
}
|
||||
os_ubuntu_setsrc (option);
|
||||
|
||||
@@ -35,7 +35,7 @@ os_alpine_prelude ()
|
||||
{&Huawei, "https://mirrors.huaweicloud.com/alpine", FeedByPrelude}
|
||||
def_sources_end()
|
||||
|
||||
chef_set_sources_speed_measure_url_with_postfix (this, "/latest-stable/releases/x86_64/alpine-standard-3.21.0-x86_64.iso");
|
||||
chef_set_all_smurl_with_postfix (this, "/latest-stable/releases/x86_64/alpine-standard-3.21.0-x86_64.iso");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ os_openwrt_prelude ()
|
||||
{&Sustech, "https://mirrors.sustech.edu.cn/openwrt", DelegateToMirror}
|
||||
def_sources_end()
|
||||
|
||||
chef_set_provider_speed_measure_url (&UpstreamProvider, "https://downloads.openwrt.org/releases/23.05.5/targets/x86/64/openwrt-sdk-23.05.5-x86-64_gcc-12.3.0_musl.Linux-x86_64.tar.xz");
|
||||
chef_set_provider_smurl (&UpstreamProvider, "https://downloads.openwrt.org/releases/23.05.5/targets/x86/64/openwrt-sdk-23.05.5-x86-64_gcc-12.3.0_musl.Linux-x86_64.tar.xz");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ os_voidlinux_prelude ()
|
||||
{&Bfsu, "https://mirrors.bfsu.edu.cn/voidlinux", FeedByPrelude}
|
||||
def_sources_end()
|
||||
|
||||
chef_set_sources_speed_measure_url_with_postfix (this, "/live/20240314/void-live-x86_64-musl-20240314-xfce.iso");
|
||||
chef_set_all_smurl_with_postfix (this, "/live/20240314/void-live-x86_64-musl-20240314-xfce.iso");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -33,8 +33,8 @@ os_almalinux_prelude ()
|
||||
def_sources_end()
|
||||
|
||||
#define link "/9.6/isos/x86_64/AlmaLinux-9-latest-x86_64-minimal.iso"
|
||||
chef_set_sources_speed_measure_url_with_postfix (this, link);
|
||||
chef_set_provider_speed_measure_url (&UpstreamProvider, "https://raw.repo.almalinux.org/almalinux" link);
|
||||
chef_set_all_smurl_with_postfix (this, link);
|
||||
chef_set_provider_smurl (&UpstreamProvider, "https://raw.repo.almalinux.org/almalinux" link);
|
||||
#undef link
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ os_openeuler_prelude ()
|
||||
// {&Sohu, "https://mirrors.sohu.com/openeuler/", FeedByPrelude}
|
||||
def_sources_end()
|
||||
|
||||
chef_set_sources_speed_measure_url_with_postfix (this, "https://repo.openeuler.org/openEuler-24.03-LTS/ISO/x86_64/openEuler-24.03-LTS-netinst-x86_64-dvd.iso");
|
||||
chef_set_all_smurl_with_postfix (this, "https://repo.openeuler.org/openEuler-24.03-LTS/ISO/x86_64/openEuler-24.03-LTS-netinst-x86_64-dvd.iso");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -31,9 +31,9 @@ wr_flatpak_prelude ()
|
||||
def_sources_end()
|
||||
|
||||
|
||||
chef_set_provider_speed_measure_url (&UpstreamProvider, "https://flathub.org/repo/flathub.gpg");
|
||||
chef_set_provider_smurl (&UpstreamProvider, "https://flathub.org/repo/flathub.gpg");
|
||||
/* upstream 默认是 ACCURATE 的,但是我们给了一个超小的文件,测速效果严重失真,所以改为 ROUGH */
|
||||
chef_set_provider_speed_measure_accuracy (&UpstreamProvider, ROUGH);
|
||||
chef_set_provider_sm_accuracy (&UpstreamProvider, ROUGH);
|
||||
|
||||
/**
|
||||
* @note 下述上海交大两个镜像站都可使用,但实际使用时出现过无法访问的情况 (GitHub-#178),
|
||||
@@ -41,11 +41,11 @@ wr_flatpak_prelude ()
|
||||
* 若无速度,则证明无法访问。
|
||||
* 注意,这会使得测速的效果严重失真。
|
||||
*/
|
||||
chef_set_provider_speed_measure_url (&Sjtug_Siyuan, "https://mirror.sjtu.edu.cn/flathub/flathub.gpg");
|
||||
chef_set_provider_speed_measure_url (&Sjtug_Zhiyuan, "https://mirrors.sjtug.sjtu.edu.cn/flathub/flathub.gpg");
|
||||
chef_set_provider_smurl (&Sjtug_Siyuan, "https://mirror.sjtu.edu.cn/flathub/flathub.gpg");
|
||||
chef_set_provider_smurl (&Sjtug_Zhiyuan, "https://mirrors.sjtug.sjtu.edu.cn/flathub/flathub.gpg");
|
||||
/* 由于实在找不到其他可测文件,所以这也只能是 ROUGH */
|
||||
chef_set_provider_speed_measure_accuracy (&Sjtug_Siyuan, ROUGH);
|
||||
chef_set_provider_speed_measure_accuracy (&Sjtug_Zhiyuan, ROUGH);
|
||||
chef_set_provider_sm_accuracy (&Sjtug_Siyuan, ROUGH);
|
||||
chef_set_provider_sm_accuracy (&Sjtug_Zhiyuan, ROUGH);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user