Use chef_

This commit is contained in:
Aoran Zeng 2025-08-11 05:05:15 +08:00
parent 67915c36c4
commit f099a86e53
No known key found for this signature in database
GPG Key ID: 8F8BA8488E10ED98
17 changed files with 84 additions and 89 deletions

View File

@ -52,12 +52,12 @@ def_sources_begin()
def_sources_end()
// 把所有上述源的测速 URL 设置为 "换源 URL" + postfix
chsrc_set_sources_speed_measure_url_with_postfix (this, "/dir/BigFile.tar.gz");
chef_set_sources_speed_measure_url_with_postfix (this, "/dir/BigFile.tar.gz");
// 基于 "换源 URL" 做更自定义的操作
chsrc_set_sources_speed_measure_url_with_func (this, func, data);
chef_set_sources_speed_measure_url_with_func (this, func, data);
// 调整某一个镜像站(Provider)的测速 URL
chsrc_set_provider_speed_measure_url (&Tencent, "https://mirrors.cloud.tencent.com/npm/BigFile.tar.gz")
chef_set_provider_speed_measure_url (&Tencent, "https://mirrors.cloud.tencent.com/npm/BigFile.tar.gz")
// 调整某一个镜像站(Provider)的测速精度
chsrc_set_provider_speed_measure_accuracy (&UpstreamProvider, ROUGH);;
chef_set_provider_speed_measure_accuracy (&UpstreamProvider, ROUGH);;
```

View File

@ -18,6 +18,66 @@
#define chef_allow_gs(t) this->getfn = t##_getsrc; this->setfn = t##_setsrc; this->resetfn = NULL;
/**
* @brief Provider
*/
void
chef_set_provider_speed_measure_url (SourceProvider_t *provider, char *url)
{
provider->psmi.skip = NotSkip;
provider->psmi.url = xy_strdup (url);
chsrc_debug ("m", xy_strjoin (4, "recipe 重新为 ", provider->code, " 设置测速链接: ", url));
}
/**
* @brief Provider
*/
void
chef_set_provider_speed_measure_accuracy (SourceProvider_t *provider, bool accuracy)
{
provider->psmi.accurate = accuracy;
chsrc_debug ("m", xy_strjoin (4, "recipe 重新为 ", provider->code, " 设置测速精度: ", accuracy ? "精准" : "粗略"));
}
/**
* @brief "换源 URL"
*/
void
chef_set_sources_speed_measure_url_with_func (
Target_t *target,
char *(*func)(const char *url, const char *user_data),
char *user_data)
{
Source_t *sources = target->sources;
int n = target->sources_n;
for (int i=0; i<n; i++)
{
Source_t *src = &sources[i];
ProviderType_t type = src->provider->type;
if (src->url)
{
/* 为空时才修改 或者里面是脏数据 */
if (NULL==src->speed_measure_url || !chef_is_url (src->speed_measure_url))
{
src->speed_measure_url = func (src->url, user_data);
}
}
}
}
/**
* @brief "换源 URL"
*/
void
chef_set_sources_speed_measure_url_with_postfix (Target_t *target, char *postfix)
{
chef_set_sources_speed_measure_url_with_func (target, xy_2strjoin, postfix);
}
void
chef_allow_english (Target_t *target)
{

View File

@ -1054,7 +1054,6 @@ chsrc_confirm_source (Source_t *source)
}
Source_t
chsrc_yield_source_and_confirm (Target_t *t, char *option)
{
@ -1064,70 +1063,6 @@ chsrc_yield_source_and_confirm (Target_t *t, char *option)
}
/**
* @brief Provider
*/
void
chsrc_set_provider_speed_measure_url (SourceProvider_t *provider, char *url)
{
provider->psmi.skip = NotSkip;
provider->psmi.url = xy_strdup (url);
chsrc_debug ("m", xy_strjoin (4, "recipe 重新为 ", provider->code, " 设置测速链接: ", url));
}
/**
* @brief Provider
*/
void
chsrc_set_provider_speed_measure_accuracy (SourceProvider_t *provider, bool accuracy)
{
provider->psmi.accurate = accuracy;
chsrc_debug ("m", xy_strjoin (4, "recipe 重新为 ", provider->code, " 设置测速精度: ", accuracy ? "精准" : "粗略"));
}
/**
* @brief "换源 URL"
*/
static void
chsrc_set_sources_speed_measure_url_with_func (
Target_t *target,
char *(*func)(const char *url, const char *user_data),
char *user_data)
{
Source_t *sources = target->sources;
int n = target->sources_n;
for (int i=0; i<n; i++)
{
Source_t *src = &sources[i];
ProviderType_t type = src->provider->type;
if (src->url)
{
/* 为空时才修改 或者里面是脏数据 */
if (NULL==src->speed_measure_url || !chef_is_url (src->speed_measure_url))
{
src->speed_measure_url = func (src->url, user_data);
}
}
}
}
/**
* @brief "换源 URL"
*/
static void
chsrc_set_sources_speed_measure_url_with_postfix (Target_t *target, char *postfix)
{
chsrc_set_sources_speed_measure_url_with_func (target, xy_2strjoin, postfix);
}
void
chsrc_determine_chgtype (ChgType_t type)
{

View File

@ -33,7 +33,7 @@ pl_dart_flutter_prelude (void)
{&Nju, "https://mirror.nju.edu.cn/flutter", FeedByPrelude}
def_sources_end()
chsrc_set_sources_speed_measure_url_with_postfix (this, "/flutter_infra_release/releases/stable/linux/flutter_linux_v1.0.0-stable.tar.xz");
chef_set_sources_speed_measure_url_with_postfix (this, "/flutter_infra_release/releases/stable/linux/flutter_linux_v1.0.0-stable.tar.xz");
}

View File

@ -33,7 +33,7 @@ pl_dart_prelude (void)
{&Nju, "https://mirror.nju.edu.cn/dart-pub", FeedByPrelude}
def_sources_end()
chsrc_set_sources_speed_measure_url_with_postfix (this, "/packages/flutter_vision/versions/1.1.4.tar.gz");
chef_set_sources_speed_measure_url_with_postfix (this, "/packages/flutter_vision/versions/1.1.4.tar.gz");
}

View File

@ -40,7 +40,7 @@ pl_js_group_prelude (void)
def_sources_end()
// 29MB 大小
chsrc_set_sources_speed_measure_url_with_postfix (this, "/@tensorflow/tfjs/-/tfjs-4.22.0.tgz");
chef_set_sources_speed_measure_url_with_postfix (this, "/@tensorflow/tfjs/-/tfjs-4.22.0.tgz");
}
@ -76,5 +76,5 @@ pl_js_nodejs_binary_prelude (void)
{&Tencent, "https://mirrors.cloud.tencent.com/nodejs-release/", FeedByPrelude}
def_sources_end()
chsrc_set_sources_speed_measure_url_with_postfix (this, "/v23.4.0/node-v23.4.0-linux-x64.tar.xz");
chef_set_sources_speed_measure_url_with_postfix (this, "/v23.4.0/node-v23.4.0-linux-x64.tar.xz");
}

View File

@ -63,7 +63,7 @@ pl_python_group_prelude (void)
// {&Netease, "https://mirrors.163.com/.help/pypi.html", NULL}
def_sources_end()
chsrc_set_sources_speed_measure_url_with_func (this, pl_python_speed_url_constructor, NULL);
chef_set_sources_speed_measure_url_with_func (this, pl_python_speed_url_constructor, NULL);
}
void

View File

@ -48,7 +48,7 @@ pl_rust_cargo_prelude (void)
{&Cqu, "https://mirrors.cqu.edu.cn/crates.io-index/", FeedByPrelude}
def_sources_end()
chsrc_set_sources_speed_measure_url_with_postfix (this, "api/v1/crates/windows/0.58.0/download");
chef_set_sources_speed_measure_url_with_postfix (this, "api/v1/crates/windows/0.58.0/download");
}

View File

@ -42,7 +42,7 @@ pl_rust_rustup_prelude (void)
def_sources_end()
// 20MB大小
chsrc_set_sources_speed_measure_url_with_postfix (this, "/dist/2025-06-26/cargo-1.88.0-x86_64-unknown-illumos.tar.gz");
chef_set_sources_speed_measure_url_with_postfix (this, "/dist/2025-06-26/cargo-1.88.0-x86_64-unknown-illumos.tar.gz");
}

View File

@ -47,7 +47,7 @@ os_debian_prelude ()
// {&Sohu, "https://mirrors.sohu.com/debian", FeedByPrelude}
def_sources_end()
chsrc_set_sources_speed_measure_url_with_postfix (this, "/dists/bookworm/main/Contents-all.gz");
chef_set_sources_speed_measure_url_with_postfix (this, "/dists/bookworm/main/Contents-all.gz");
}

View File

@ -48,7 +48,7 @@ os_ubuntu_prelude ()
// {&Sohu, "https://mirrors.sohu.com/ubuntu", FeedByPrelude}
def_sources_end()
chsrc_set_sources_speed_measure_url_with_postfix (this, "/dists/noble/Contents-amd64.gz");
chef_set_sources_speed_measure_url_with_postfix (this, "/dists/noble/Contents-amd64.gz");
}

View File

@ -38,7 +38,7 @@ os_alpine_prelude ()
{&Huawei, "https://mirrors.huaweicloud.com/alpine", FeedByPrelude}
def_sources_end()
chsrc_set_sources_speed_measure_url_with_postfix (this, "/latest-stable/releases/x86_64/alpine-standard-3.21.0-x86_64.iso");
chef_set_sources_speed_measure_url_with_postfix (this, "/latest-stable/releases/x86_64/alpine-standard-3.21.0-x86_64.iso");
}

View File

@ -39,7 +39,7 @@ os_openwrt_prelude ()
{&Sustech, "https://mirrors.sustech.edu.cn/openwrt", DelegateToMirror}
def_sources_end()
chsrc_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_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");
}

View File

@ -33,7 +33,7 @@ os_voidlinux_prelude ()
{&Bfsu, "https://mirrors.bfsu.edu.cn/voidlinux", FeedByPrelude}
def_sources_end()
chsrc_set_sources_speed_measure_url_with_postfix (this, "/live/20240314/void-live-x86_64-musl-20240314-xfce.iso");
chef_set_sources_speed_measure_url_with_postfix (this, "/live/20240314/void-live-x86_64-musl-20240314-xfce.iso");
}

View File

@ -35,7 +35,7 @@ os_almalinux_prelude ()
{&Nju, "https://mirror.nju.edu.cn/almalinux", FeedByPrelude}
def_sources_end()
chsrc_set_provider_speed_measure_url (&UpstreamProvider, "https://raw.repo.almalinux.org/almalinux/9.5/isos/x86_64/AlmaLinux-9-latest-x86_64-minimal.iso");
chef_set_provider_speed_measure_url (&UpstreamProvider, "https://raw.repo.almalinux.org/almalinux/9.5/isos/x86_64/AlmaLinux-9-latest-x86_64-minimal.iso");
}
/**

View File

@ -44,7 +44,7 @@ os_openeuler_prelude ()
// {&Sohu, "https://mirrors.sohu.com/openeuler/", FeedByPrelude}
def_sources_end()
chsrc_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_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");
}

View File

@ -34,9 +34,9 @@ wr_flatpak_prelude ()
def_sources_end()
chsrc_set_provider_speed_measure_url (&UpstreamProvider, "https://flathub.org/repo/flathub.gpg");
chef_set_provider_speed_measure_url (&UpstreamProvider, "https://flathub.org/repo/flathub.gpg");
/* upstream 默认是 ACCURATE 的,但是我们给了一个超小的文件,测速效果严重失真,所以改为 ROUGH */
chsrc_set_provider_speed_measure_accuracy (&UpstreamProvider, ROUGH);
chef_set_provider_speed_measure_accuracy (&UpstreamProvider, ROUGH);
/**
* @note 使使访 (GitHub-#178)
@ -44,11 +44,11 @@ wr_flatpak_prelude ()
* 访
* 使
*/
chsrc_set_provider_speed_measure_url (&Sjtug_Siyuan, "https://mirror.sjtu.edu.cn/flathub/flathub.gpg");
chsrc_set_provider_speed_measure_url (&Sjtug_Zhiyuan, "https://mirrors.sjtug.sjtu.edu.cn/flathub/flathub.gpg");
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");
/* 由于实在找不到其他可测文件,所以这也只能是 ROUGH */
chsrc_set_provider_speed_measure_accuracy (&Sjtug_Siyuan, ROUGH);
chsrc_set_provider_speed_measure_accuracy (&Sjtug_Zhiyuan, ROUGH);
chef_set_provider_speed_measure_accuracy (&Sjtug_Siyuan, ROUGH);
chef_set_provider_speed_measure_accuracy (&Sjtug_Zhiyuan, ROUGH);
}