修复CDN URL和路径构建逻辑

- 修复CDN URL构建,正确处理路径重复问题
- 修复rclone路径构建,使用正确的格式: {rclone_remote}:{storage_path}/{version_path}/{filename}
- 修复CDN路径构建,使用正确的格式: {cdn_base_url}/{version_path}/{filename}
- 修复CDN内容解密处理,支持加密和解密后的内容
- 添加路径构建测试示例
- 完善错误处理和空内容处理
This commit is contained in:
2025-08-07 18:03:16 +08:00
parent 4cb6c4eab7
commit 9eddb3133c
13 changed files with 675 additions and 32 deletions

View File

@@ -2,6 +2,7 @@ import click
import os
from ..core.view_command import ViewCommand
from ..utils.mock_rclone import patch_rclone
from ..utils.config import config
@click.group()
@@ -18,8 +19,8 @@ def cli():
@cli.command()
@click.option('--version', required=True, help='版本号,格式为 0.29, 0.30, 0.31 等')
@click.option('--json', 'json_format', is_flag=True, help='以JSON格式输出')
@click.option('--storage-path', default='ab', help='对象存储路径前缀')
@click.option('--cdn-url', default='', help='CDN基础URL')
@click.option('--storage-path', help='对象存储路径前缀(覆盖配置文件)')
@click.option('--cdn-url', help='CDN基础URL(覆盖配置文件)')
@click.option('--mock', is_flag=True, help='使用模拟环境进行测试')
def view(version, json_format, storage_path, cdn_url, mock):
"""查看配置文件
@@ -89,6 +90,67 @@ def force_update(platform, target_version, update_version):
return 1
@cli.command()
def show_config():
"""显示当前配置
显示当前加载的配置信息。
"""
import json
from rich.console import Console
from rich.panel import Panel
console = Console()
# 获取所有配置
all_config = {
"storage": config.get_storage_config(),
"cdn": config.get_cdn_config(),
"crypto": config.get_crypto_config(),
"display": config.get_display_config(),
"logging": config.get_logging_config()
}
# 格式化输出
config_json = json.dumps(all_config, indent=2, ensure_ascii=False)
panel = Panel(
config_json,
title="当前配置",
border_style="blue"
)
console.print(panel)
# 显示配置文件路径
console.print(f"\n配置文件路径: {config.config_file}")
@cli.command()
@click.option('--key', required=True, help='配置键,如 storage.path')
@click.option('--value', required=True, help='配置值')
def set_config(key, value):
"""设置配置值
设置指定的配置值并保存到配置文件。
示例:
config-man set-config --key storage.path --value custom_path
config-man set-config --key cdn.base_url --value https://cdn.example.com
"""
try:
# 尝试转换数值类型
if value.isdigit():
value = int(value)
elif value.lower() in ('true', 'false'):
value = value.lower() == 'true'
config.set(key, value)
config.save()
click.echo(f"✅ 配置已更新: {key} = {value}")
except Exception as e:
click.echo(f"❌ 设置配置失败: {e}")
return 1
def _check_rclone():
"""检查rclone是否可用"""
import subprocess