feat(cache): 上游模型加多源 sources 字段
旧 JSON 无该字段时走 serde default ⇒ 存量文件不用改、行为不变。
This commit is contained in:
1 parent
877ab5eaf4
commit
838f497290
1 file changed
+30
@@ -34,6 +34,32 @@ impl Default for CacheUpstreamStore {
|
||||
}
|
||||
}
|
||||
|
||||
/// 多源模式下的**一条上游源**。
|
||||
///
|
||||
/// 与 `CacheUpstream.base` 的区别:`base` 是「这条路由的上游」,
|
||||
/// `sources` 是「这条路由的**镜像池**」——插件在池里轮转选源,
|
||||
/// 失败的那个进冷却、下次直接跳过。
|
||||
///
|
||||
/// ⚠️ `url` 与 `base` 同约定:**不含**路由的协议前缀
|
||||
/// (docker 的 `/v2` 由插件在 tail 侧补,见 `config::upstream_path_prefix`)。
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
pub struct CacheSource {
|
||||
/// 稳定标识(小写字母/数字/`-`),管理台展示与冷却键用;
|
||||
/// 留空时由 `url` 的 host 自动生成。
|
||||
#[serde(default)]
|
||||
pub id: String,
|
||||
/// 上游 URL:`scheme://host[/镜像自己的路径前缀]`,不带尾斜杠。
|
||||
#[serde(default)]
|
||||
pub url: String,
|
||||
/// 该源自己的凭据(完整 `Authorization` 头值)。
|
||||
/// 空 = 用路由级 `key`;路由级也空 = 透传客户端的 `Authorization`。
|
||||
#[serde(default)]
|
||||
pub key: String,
|
||||
/// 备注
|
||||
#[serde(default)]
|
||||
pub note: String,
|
||||
}
|
||||
|
||||
/// 单个生态的上游配置。
|
||||
///
|
||||
/// 这里刻意**不存**「把哪个 URI 前缀映射到本生态」——那由 nginx conf 的
|
||||
@@ -50,6 +76,9 @@ pub struct CacheUpstream {
|
||||
/// Authorization,Docker Hub 的 Bearer token 走这条;但下端 `sk_` 会被剔除)。
|
||||
#[serde(default)]
|
||||
pub key: String,
|
||||
/// 镜像源池(非空 = 多源模式)。空 = 退回单 `base` 模式(今天的行为)。
|
||||
#[serde(default)]
|
||||
pub sources: Vec<CacheSource>,
|
||||
/// 模式(见 `config::MODE_PROXY`)
|
||||
#[serde(default = "default_mode")]
|
||||
pub mode: String,
|
||||
@@ -83,6 +112,7 @@ impl Default for CacheUpstream {
|
||||
Self {
|
||||
base: String::new(),
|
||||
key: String::new(),
|
||||
sources: Vec::new(),
|
||||
mode: default_mode(),
|
||||
name: String::new(),
|
||||
desc: String::new(),
|
||||
|
||||
Reference in new issue
Block a user