From c86cbc473f73788014f9a07442956137f9d06fd7 Mon Sep 17 00:00:00 2001 From: ZhaoML Date: Tue, 9 Sep 2025 17:27:44 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat(cloudflarespeedtest):=20=E9=80=82?= =?UTF-8?q?=E9=85=8D=20CloudflareSpeedTest=20=E6=96=B0=E7=89=88=E5=90=8D?= =?UTF-8?q?=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 更新插件版本至 1.5 - 修改二进制文件名称从 CloudflareST 到 cfst - 增加旧版本兼容性处理 - 更新下载链接和安装逻辑以适应新名称 - 在 package.json 中添加新版本历史记录 --- package.json | 3 +- plugins/cloudflarespeedtest/__init__.py | 47 ++++++++++++++++++------- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 89a054b..1084c9f 100644 --- a/package.json +++ b/package.json @@ -217,12 +217,13 @@ "name": "Cloudflare IP优选", "description": "🌩 测试 Cloudflare CDN 延迟和速度,自动优选IP。", "labels": "网络,站点", - "version": "1.4", + "version": "1.5", "icon": "cloudflare.jpg", "author": "thsrite", "level": 1, "v2": true, "history": { + "v1.5": "适配CloudflareSpeedTest新版名称", "v1.4": "修复立即运行一次", "v1.3": "调整插件开启状态判断条件", "v1.2": "增强API安全性" diff --git a/plugins/cloudflarespeedtest/__init__.py b/plugins/cloudflarespeedtest/__init__.py index 07fab1a..15e2a82 100644 --- a/plugins/cloudflarespeedtest/__init__.py +++ b/plugins/cloudflarespeedtest/__init__.py @@ -32,7 +32,7 @@ class CloudflareSpeedTest(_PluginBase): # 插件图标 plugin_icon = "cloudflare.jpg" # 插件版本 - plugin_version = "1.4" + plugin_version = "1.5" # 插件作者 plugin_author = "thsrite" # 作者主页 @@ -62,7 +62,8 @@ class CloudflareSpeedTest(_PluginBase): _cf_ipv6 = None _result_file = None _release_prefix = 'https://github.com/XIU2/CloudflareSpeedTest/releases/download' - _binary_name = 'CloudflareST' + _binary_name = 'cfst' + _old_binary_name = 'CloudflareST' def init_plugin(self, config: dict = None): # 停止现有任务 @@ -156,12 +157,23 @@ class CloudflareSpeedTest(_PluginBase): logger.info("正在进行CLoudflare CDN优选,请耐心等待") # 执行优选命令,-dd不测速 if SystemUtils.is_windows(): - cf_command = f'cd \"{self._cf_path}\" && CloudflareST {self._additional_args} -o \"{self._result_file}\"' + ( + cf_command = f'cd \"{self._cf_path}\" && {self._binary_name} {self._additional_args} -o \"{self._result_file}\"' + ( f' -f \"{self._cf_ipv4}\"' if self._ipv4 else '') + ( f' -f \"{self._cf_ipv6}\"' if self._ipv6 else '') + # 兼容旧版本 + if not Path(f'{self._cf_path}/{self._binary_name}.exe').exists() and \ + Path(f'{self._cf_path}/{self._old_binary_name}.exe').exists(): + cf_command = f'cd \"{self._cf_path}\" && {self._old_binary_name} {self._additional_args} -o \"{self._result_file}\"' + ( + f' -f \"{self._cf_ipv4}\"' if self._ipv4 else '') + ( + f' -f \"{self._cf_ipv6}\"' if self._ipv6 else '') else: cf_command = f'cd {self._cf_path} && chmod a+x {self._binary_name} && ./{self._binary_name} {self._additional_args} -o {self._result_file}' + ( f' -f {self._cf_ipv4}' if self._ipv4 else '') + (f' -f {self._cf_ipv6}' if self._ipv6 else '') + # 兼容旧版本 + if not Path(f'{self._cf_path}/{self._binary_name}').exists() and \ + Path(f'{self._cf_path}/{self._old_binary_name}').exists(): + cf_command = f'cd {self._cf_path} && chmod a+x {self._old_binary_name} && ./{self._old_binary_name} {self._additional_args} -o {self._result_file}' + ( + f' -f {self._cf_ipv4}' if self._ipv4 else '') + (f' -f {self._cf_ipv6}\"' if self._ipv6 else '') logger.info(f'正在执行优选命令 {cf_command}') if SystemUtils.is_windows(): process = subprocess.Popen(cf_command, shell=True) @@ -173,7 +185,10 @@ class CloudflareSpeedTest(_PluginBase): time.sleep(600) # 如果没有在120秒内完成任务,那么杀死该进程 if process.poll() is None: - os.system('taskkill /F /IM CloudflareST.exe') + os.system(f'taskkill /F /IM {self._binary_name}.exe') + # 兼容旧版本 + if not Path(f'{self._cf_path}/{self._binary_name}.exe').exists(): + os.system(f'taskkill /F /IM {self._old_binary_name}.exe') else: os.system(cf_command) @@ -319,7 +334,8 @@ class CloudflareSpeedTest(_PluginBase): and release_version == self._version \ and not Path( f'{self._cf_path}/{self._binary_name}').exists() \ - and not Path(f'{self._cf_path}/CloudflareST.exe').exists(): + and not Path(f'{self._cf_path}/{self._old_binary_name}').exists() \ + and not Path(f'{self._cf_path}/{self._binary_name}.exe').exists(): logger.warn(f"未检测到CloudflareSpeedTest本地版本,重新安装") install_flag = True @@ -330,7 +346,7 @@ class CloudflareSpeedTest(_PluginBase): # 检查环境、安装 if SystemUtils.is_windows(): # windows - cf_file_name = 'CloudflareST_windows_amd64.zip' + cf_file_name = f'{self._binary_name}_windows_amd64.zip' download_url = f'{self._release_prefix}/{release_version}/{cf_file_name}' return self.__os_install(download_url, cf_file_name, release_version, f"ditto -V -x -k --sequesterRsrc {self._cf_path}/{cf_file_name} {self._cf_path}") @@ -338,7 +354,7 @@ class CloudflareSpeedTest(_PluginBase): # mac uname = SystemUtils.execute('uname -m') arch = 'amd64' if uname == 'x86_64' else 'arm64' - cf_file_name = f'CloudflareST_darwin_{arch}.zip' + cf_file_name = f'{self._binary_name}_darwin_{arch}.zip' download_url = f'{self._release_prefix}/{release_version}/{cf_file_name}' return self.__os_install(download_url, cf_file_name, release_version, f"ditto -V -x -k --sequesterRsrc {self._cf_path}/{cf_file_name} {self._cf_path}") @@ -346,7 +362,7 @@ class CloudflareSpeedTest(_PluginBase): # docker uname = SystemUtils.execute('uname -m') arch = 'amd64' if uname == 'x86_64' else 'arm64' - cf_file_name = f'CloudflareST_linux_{arch}.tar.gz' + cf_file_name = f'{self._binary_name}_linux_{arch}.tar.gz' download_url = f'{self._release_prefix}/{release_version}/{cf_file_name}' return self.__os_install(download_url, cf_file_name, release_version, f"tar -zxf {self._cf_path}/{cf_file_name} -C {self._cf_path}") @@ -370,7 +386,8 @@ class CloudflareSpeedTest(_PluginBase): if SystemUtils.is_windows(): self.__get_windows_cloudflarest(download_url, proxies) else: - os.system(f'wget -P {self._cf_path} https://ghproxy.com/{download_url}') + proxy_host = os.environ.get("PROXY_HOST", "https://ghfast.top") + os.system(f'wget -P {self._cf_path} {proxy_host}/{download_url}') # 判断是否下载好安装包 if Path(f'{self._cf_path}/{cf_file_name}').exists(): @@ -379,7 +396,8 @@ class CloudflareSpeedTest(_PluginBase): with zipfile.ZipFile(f'{self._cf_path}/{cf_file_name}', 'r') as zip_ref: # 解压ZIP文件中的所有文件到指定目录 zip_ref.extractall(self._cf_path) - if Path(f'{self._cf_path}\\CloudflareST.exe').exists(): + if Path(f'{self._cf_path}\\{self._binary_name}.exe').exists() or \ + Path(f'{self._cf_path}\\{self._old_binary_name}.exe').exists(): logger.info(f"CloudflareSpeedTest安装成功,当前版本:{release_version}") return True, release_version else: @@ -390,7 +408,8 @@ class CloudflareSpeedTest(_PluginBase): os.system(f'{unzip_command}') # 删除压缩包 os.system(f'rm -rf {self._cf_path}/{cf_file_name}') - if Path(f'{self._cf_path}/{self._binary_name}').exists(): + if Path(f'{self._cf_path}/{self._binary_name}').exists() or \ + Path(f'{self._cf_path}/{self._old_binary_name}').exists(): logger.info(f"CloudflareSpeedTest安装成功,当前版本:{release_version}") return True, release_version else: @@ -413,7 +432,9 @@ class CloudflareSpeedTest(_PluginBase): else: # 如果升级失败但是有可执行文件CloudflareST,则可继续运行,反之停止 if Path(f'{self._cf_path}/{self._binary_name}').exists() or \ - Path(f'{self._cf_path}\\CloudflareST.exe').exists(): + Path(f'{self._cf_path}\\{self._binary_name}.exe').exists() or \ + Path(f'{self._cf_path}/{self._old_binary_name}').exists() or \ + Path(f'{self._cf_path}\\{self._old_binary_name}.exe').exists(): logger.warn(f"CloudflareSpeedTest安装失败,存在可执行版本,继续运行") return True, None else: @@ -431,7 +452,7 @@ class CloudflareSpeedTest(_PluginBase): except requests.exceptions.RequestException as e: logger.error(f"CloudflareSpeedTest下载失败:{str(e)}") if response.status_code == 200: - with open(f'{self._cf_path}\\CloudflareST_windows_amd64.zip', 'wb') as file: + with open(f'{self._cf_path}\\{self._binary_name}_windows_amd64.zip', 'wb') as file: for chunk in response.iter_content(chunk_size=8192): file.write(chunk) From 624594046656ce0d1b698d9506d91035cdf67113 Mon Sep 17 00:00:00 2001 From: ZhaoML Date: Tue, 9 Sep 2025 17:52:06 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix(Cloudflare=20IP=E4=BC=98=E9=80=89):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20IPv6=20=E5=9C=B0=E5=9D=80=E5=90=AB?= =?UTF-8?q?=E5=8F=8C=E5=BC=95=E5=8F=B7=E5=AF=BC=E8=87=B4=E7=9A=84=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E9=94=99=E8=AF=AF=20-=20=E7=A7=BB=E9=99=A4=E4=BA=86?= =?UTF-8?q?=20cloudflarespeedtest=20=E6=8F=92=E4=BB=B6=E4=B8=AD=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E5=91=BD=E4=BB=A4=E6=97=B6=E5=AF=B9=20IPv6=20?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=E7=9A=84=E5=8F=8C=E5=BC=95=E5=8F=B7=20-=20?= =?UTF-8?q?=E8=AF=A5=E4=BF=AE=E6=94=B9=E8=A7=A3=E5=86=B3=E4=BA=86=E5=BD=93?= =?UTF-8?q?=20IPv6=20=E5=9C=B0=E5=9D=80=E5=8C=85=E5=90=AB=E5=8F=8C?= =?UTF-8?q?=E5=BC=95=E5=8F=B7=E6=97=B6=EF=BC=8C=E5=91=BD=E4=BB=A4=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E6=AD=A3=E7=A1=AE=E6=89=A7=E8=A1=8C=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/cloudflarespeedtest/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/cloudflarespeedtest/__init__.py b/plugins/cloudflarespeedtest/__init__.py index 15e2a82..1e4b651 100644 --- a/plugins/cloudflarespeedtest/__init__.py +++ b/plugins/cloudflarespeedtest/__init__.py @@ -173,7 +173,7 @@ class CloudflareSpeedTest(_PluginBase): if not Path(f'{self._cf_path}/{self._binary_name}').exists() and \ Path(f'{self._cf_path}/{self._old_binary_name}').exists(): cf_command = f'cd {self._cf_path} && chmod a+x {self._old_binary_name} && ./{self._old_binary_name} {self._additional_args} -o {self._result_file}' + ( - f' -f {self._cf_ipv4}' if self._ipv4 else '') + (f' -f {self._cf_ipv6}\"' if self._ipv6 else '') + f' -f {self._cf_ipv4}' if self._ipv4 else '') + (f' -f {self._cf_ipv6}' if self._ipv6 else '') logger.info(f'正在执行优选命令 {cf_command}') if SystemUtils.is_windows(): process = subprocess.Popen(cf_command, shell=True)