## CC 匹配器 (`cc-matches`)

CC 防护里用来识别请求的条件;可复用到多个规则组。

鉴权: 用户（部分参数仅管理员） · 文档: https://www-demo.kuxitong.com/zh/docs/api/cc-matches

### GET `/api/v2/cc-matches`

列出CC 匹配器 · 鉴权: 用户（部分参数仅管理员）

查询参数:

| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| `page` | integer |  | 页码,从 1 开始。 默认: 1 |
| `page_size` | integer |  | 每页条数。 默认: 20 |
| `sort` | string |  | 排序字段,逗号分隔,前缀 `-` 表示降序,如 `-created_at,id`。 |
| `tenant_id` | integer |  | 仅管理员可用:按租户过滤。租户凭据调用时忽略,只返回本租户数据。 |
| `name` | string |  | 按名称包含过滤。 |
| `owner` | string |  | platform = 只看平台对象;tenant = 只看租户对象。 可选值: ["platform","tenant"] |

```sh
curl "https://panel.example.com/api/v2/cc-matches" \
  -H "X-API-Key: $GOCDN_API_KEY"
```

### POST `/api/v2/cc-matches`

创建CC 匹配器 · 鉴权: 用户（部分参数仅管理员）

请求体:

| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| `des` | string |  | 备注;不给则为空(修改时不给也清空,整体替换)。 |
| `name` | string | 有 | 名称 |
| `when` | object |  | 规则 DSL 条件:all/any/not 组合,或 {f, op, v, set, neg} 叶子;由 internal/ruledsl 校验,错误以 422 透传(field 为 JSON Pointer,code 为小写的 ruledsl 错误码)。 null = 匹配全部。 |

```sh
curl -X POST "https://panel.example.com/api/v2/cc-matches" \
  -H "X-API-Key: $GOCDN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name":"static","when":{"f":"req_uri","op":"contains","v":[".js",".css"]}}'
```

### POST `/api/v2/cc-matches/replay`

回放CC 匹配器草稿 · 鉴权: 用户（部分参数仅管理员）

请求体:

| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| `site_id` | integer |  | 只算这个网站的流量;不给 = 当前身份可见的全部网站。 |
| `when` | object |  | 规则 DSL 条件:all/any/not 组合,或 {f, op, v, set, neg} 叶子;由 internal/ruledsl 校验,错误以 422 透传(field 为 JSON Pointer,code 为小写的 ruledsl 错误码)。 null = 匹配全部。 |

```sh
curl -X POST "https://panel.example.com/api/v2/cc-matches/replay" \
  -H "X-API-Key: $GOCDN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"when":{"f":"ja4","op":"eq","v":["t13d1516h2_8daaf6152771_e5627efa2ab1"]}}'
```

### GET `/api/v2/cc-matches/{id}`

获取CC 匹配器 · 鉴权: 用户（部分参数仅管理员）

```sh
curl "https://panel.example.com/api/v2/cc-matches/{id}" \
  -H "X-API-Key: $GOCDN_API_KEY"
```

### PUT `/api/v2/cc-matches/{id}`

修改CC 匹配器 · 鉴权: 用户（部分参数仅管理员）

请求体:

| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| `des` | string |  | 备注;不给则为空(修改时不给也清空,整体替换)。 |
| `name` | string | 有 | 名称 |
| `when` | object |  | 规则 DSL 条件:all/any/not 组合,或 {f, op, v, set, neg} 叶子;由 internal/ruledsl 校验,错误以 422 透传(field 为 JSON Pointer,code 为小写的 ruledsl 错误码)。 null = 匹配全部。 |

```sh
curl -X PUT "https://panel.example.com/api/v2/cc-matches/{id}" \
  -H "X-API-Key: $GOCDN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name":"static","when":{"f":"req_uri","op":"contains","v":[".js",".css"]}}'
```

### DELETE `/api/v2/cc-matches/{id}`

删除CC 匹配器 · 鉴权: 用户（部分参数仅管理员）

```sh
curl -X DELETE "https://panel.example.com/api/v2/cc-matches/{id}" \
  -H "X-API-Key: $GOCDN_API_KEY"
```

CC 匹配器对象:

| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| `builtin` | boolean |  | 内置对象,不可删。 (只读) |
| `created_at` | string |  | 创建时间 (只读) |
| `des` | string |  | 备注;不给则为空(修改时不给也清空,整体替换)。 |
| `hits` | integer |  | 窗口内命中的请求数(按 sample_weight 还原)。 |
| `id` | integer |  | 记录 ID (只读) |
| `ips` | integer |  | 命中请求涉及的不同客户端 IP 数(去重计数,不按采样还原)。 |
| `name` | string |  | 名称 |
| `reason` | string |  | supported=false 时的说明。 |
| `sampled` | boolean |  | 窗口内有被采样的行(sample_weight > 1);此时 hits、total 是估计值。 |
| `site_id` | integer |  | 只算这个网站的流量;不给 = 当前身份可见的全部网站。 |
| `sites` | integer |  | 命中请求涉及的不同网站数(去重计数,不按采样还原)。 |
| `supported` | boolean |  | false = 条件里有访问日志没有的字段(请求头、accept_language、命名集合),没有回放;原因见 reason。 |
| `tenant_id` | integer |  | 所属租户;null = 平台对象(内置或管理员建,租户只读)。 (只读) |
| `top_ips` | CcMatchReplayIp[] |  | 命中请求最多的客户端 IP,最多 20 条,按请求数降序;supported=false 或没有命中时为空。 |
| `top_urls` | CcMatchReplayUrl[] |  | 命中请求最多的 URL(不含查询串),最多 5 条,按请求数降序;supported=false 或没有命中时为空。 |
| `total` | integer |  | 窗口内的请求总数(同样还原)。 |
| `updated_at` | string |  | 更新时间 (只读) |
| `when` | object |  | 规则 DSL 条件:all/any/not 组合,或 {f, op, v, set, neg} 叶子;由 internal/ruledsl 校验,错误以 422 透传(field 为 JSON Pointer,code 为小写的 ruledsl 错误码)。 null = 匹配全部。 |
| `window_hours` | integer |  | 回放窗口小时数(固定 24)。 |
