Change to npmmirror and use a new url for cesu [Gitee close #I7ZC7R]

This commit is contained in:
Aoran Zeng
2023-09-09 16:49:06 +08:00
parent 3a28d8e7b7
commit 25fa229852
2 changed files with 50 additions and 31 deletions

47
chsrc.c
View File

@@ -1,16 +1,16 @@
/* -------------------------------------------------------------- /** ------------------------------------------------------------
* File : chsrc.c * File : chsrc.c
* License : GPLv3 * License : GPLv3
* Authors : Aoran Zeng <ccmywish@qq.com> * Authors : Aoran Zeng <ccmywish@qq.com>
* Created on : <2023-08-28> * Created on : <2023-08-28>
* Last modified : <2023-09-08> * Last modified : <2023-09-09>
* *
* chsrc: * chsrc:
* *
* Change Source —— 命令行换源工具 * Change Source —— 命令行换源工具
* *
* 该软件为自由软件,采用 GPLv3 许可证,请查阅 LICENSE.txt 文件 * 该软件为自由软件,采用 GPLv3 许可证,请查阅 LICENSE.txt 文件
* -------------------------------------------------------------*/ * ------------------------------------------------------------*/
#include "chsrc.h" #include "chsrc.h"
@@ -92,6 +92,9 @@ does_the_input_mirror_exist (source_info* sources, size_t size, char* target, ch
return idx; return idx;
} }
/**
* 该函数来自 oh-my-mirrorz.py由我(@ccmywish)翻译为C语言但功劳和版权属于原作者
*/
char* char*
to_human_readable_speed (double speed) to_human_readable_speed (double speed)
{ {
@@ -118,16 +121,28 @@ to_human_readable_speed (double speed)
/** /**
* 测速代码参考自 https://github.com/mirrorz-org/oh-my-mirrorz/blob/master/oh-my-mirrorz.py * 测速代码参考自 https://github.com/mirrorz-org/oh-my-mirrorz/blob/master/oh-my-mirrorz.py
* 修改为C语言一切功劳属于原作者 * 功劳和版权属于原作者,由我(@ccmywish)修改为C语言并做了额外调整。
* *
* @return 返回测得的速度,若出错,返回-1 * @return 返回测得的速度,若出错,返回-1
*/ */
double double
test_speed_url (const char* url) test_speed_url (const char* url)
{ {
char* time_sec = "6";
/* 现在我们切换至跳转后的链接来测速,不再使用下述判断
if (xy_str_start_with(url, "https://registry.npmmirror"))
{
// 这里 npmmirror 跳转非常慢需要1~3秒所以我们给它留够至少8秒测速时间否则非常不准
time_sec = "10";
}
*/
// 我们用 —L因为Ruby China源会跳转到其他地方 // 我们用 —L因为Ruby China源会跳转到其他地方
char* curl_cmd = xy_strjoin(4, "curl -qsL -o ", xy_os_devnull, " -w \"%{http_code} %{speed_download}\" -m6 -A chsrc/" Chsrc_Version // npmmirror 也会跳转
" ", url); char* curl_cmd = xy_strjoin(6, "curl -qsL -o ", xy_os_devnull,
" -w \"%{http_code} %{speed_download}\" -m", time_sec ,
" -A chsrc/" Chsrc_Version " ", url);
// xy_info (xy_2strjoin("chsrc: 测速 ", url)); // xy_info (xy_2strjoin("chsrc: 测速 ", url));

34
chsrc.h
View File

@@ -1,14 +1,14 @@
/* -------------------------------------------------------------- /** ------------------------------------------------------------
* File : chsrc.h * File : chsrc.h
* License : GPLv3 * License : GPLv3
* Authors : Aoran Zeng <ccmywish@qq.com> * Authors : Aoran Zeng <ccmywish@qq.com>
* Created on : <2023-08-29> * Created on : <2023-08-29>
* Last modified : <2023-09-05> * Last modified : <2023-09-09>
* *
* chsrc: * chsrc:
* *
* chsrc.c 头文件 * chsrc.c 头文件
* -------------------------------------------------------------*/ * ------------------------------------------------------------*/
#include "xy.h" #include "xy.h"
@@ -95,7 +95,11 @@ mirror_info
RubyChina = {"rubychina", "RubyChina", "Ruby China 社区", "https://gems.ruby-china.com/", RubyChina = {"rubychina", "RubyChina", "Ruby China 社区", "https://gems.ruby-china.com/",
"https://gems.ruby-china.com/rubygems/gems/nokogiri-1.15.0-java.gem"}, // 9.9 MB "https://gems.ruby-china.com/rubygems/gems/nokogiri-1.15.0-java.gem"}, // 9.9 MB
GoProxyCN = {"goproxy.cn", "Goproxy.cn", "七牛云 Goproxy.cn", "https://goproxy.cn/", NpmMirror = {"npmmirror", "npmmirror", "npmmirror (阿里云赞助)", "https://npmmirror.com/",
// 注意,这个是跳转后的地址,不确定未来会不会改变
"https://cdn.npmmirror.com/packages/%40tensorflow/tfjs/4.10.0/tfjs-4.10.0.tgz"}, // 29MB
GoProxyCN = {"goproxy.cn", "Goproxy.cn", "Goproxy.cn (七牛云赞助)", "https://goproxy.cn/",
"https://goproxy.cn/github.com/aws/aws-sdk-go/@v/v1.45.2.zip"}, // 30 MB "https://goproxy.cn/github.com/aws/aws-sdk-go/@v/v1.45.2.zip"}, // 30 MB
GoProxyIO = {"goproxy.io", "GOPROXY.IO", "GOPROXY.IO", "https://goproxy.io/", GoProxyIO = {"goproxy.io", "GOPROXY.IO", "GOPROXY.IO", "https://goproxy.io/",
@@ -108,7 +112,7 @@ mirror_info*
available_mirrors[] = { available_mirrors[] = {
&MirrorZ, &Tuna, &Sjtug_Zhiyuan, &Zju, &Lzuoss, &Jlu, &Bfsu, &Pku, &Bjtu, &Sustech, &Ustc, &Nju, // &Cqu, &MirrorZ, &Tuna, &Sjtug_Zhiyuan, &Zju, &Lzuoss, &Jlu, &Bfsu, &Pku, &Bjtu, &Sustech, &Ustc, &Nju, // &Cqu,
&Ali, &Tencent, &Netease, &Sohu, &Ali, &Tencent, &Netease, &Sohu,
&RubyChina, &GoProxyCN, &GoProxyIO &RubyChina, &NpmMirror, &GoProxyCN, &GoProxyIO
// 暂不支持 &NugetOrg // 暂不支持 &NugetOrg
}; };
@@ -161,14 +165,14 @@ pl_python_sources[] = {
/** /**
* 2023-08-30 更新 * 2023-09-09 更新
* *
* Sjtug, Tuna, Lzuoss, Jlu, Bfsu, 网易,搜狐 都没有 * Sjtug, Tuna, Lzuoss, Jlu, Bfsu, 网易,搜狐 都没有
* *
* @note 腾讯软件源虽然有npm的名但名存实亡 * @note 腾讯软件源虽然有npm的名但名存实亡
*/ */
pl_nodejs_sources[] = { pl_nodejs_sources[] = {
{&Ali, "https://registry.npmmirror.com"}, {&NpmMirror, "https://registry.npmmirror.com"},
{&Zju, "https://mirrors.zju.edu.cn/docs/npm/"} {&Zju, "https://mirrors.zju.edu.cn/docs/npm/"}
}, },