Skip to main content

compose_url

Function compose_url 

Source
pub fn compose_url(reference: &str, cfg: &Value) -> Result<String, String>
Expand description

URL 纯组合(无 IO)。cfg: { “baseUrl”: “https://cdn.example.com”, “pathTemplate”: “/{contentPath}”, // 默认 “{key}”;可用 {key}/{sha1}/{contentPath} “query”: { “x-oss-process”: “image/resize,w_{w}” }, // 值内可含 {var} “vars”: { “w”: “200”, “h”: “100” }, // 供模板与 query 值替换 “externalPassthrough”: true // 默认 true;false 时遇外部 URL 显式 Err }

规则:

  1. reference 为空 → Err;
  2. 外部 URL:externalPassthrough(默认 true)→ 原样返回;显式 false → Err;
  3. 内部 id:baseUrl 与渲染后的 path 拼接(缺斜杠自动补一个),query 按键名排序追加并 percent-encode。