{
  "tags": [
    "CC 防护"
  ],
  "description": "为当前登录用户创建一个 CC 过滤器，创建前会按照当前账号的网站数量和系统配置检查可创建的站点关联对象配额；同一所属用户下过滤器名称不可重复。普通用户只能创建归属于自己的自定义过滤器，管理员可通过请求体指定所属用户或创建系统内置过滤器。`req_rate` 类型必须配置单 URI 请求上限，`url_auth` 类型必须配置 URL 鉴权参数；其他类型的扩展配置会以空对象保存。新增过滤器固定以启用状态和版本 1 写入。",
  "operationId": "user_post_v1_cc_filters",
  "security": [
    {
      "AccessToken": []
    },
    {
      "ApiKey": [],
      "ApiSecret": []
    }
  ],
  "responses": {
    "200": {
      "description": "业务结果通过 HTTP 200 返回。创建成功时返回新过滤器 ID；配额不足、名称或阈值不合法、类型条件字段缺失、URL 鉴权配置错误、管理员专属字段越权、系统维护或认证失效时返回字符串业务错误码，数据库事务会回滚。",
      "content": {
        "application/json": {
          "schema": {
            "oneOf": [
              {
                "type": "object",
                "required": [
                  "code",
                  "msg",
                  "data"
                ],
                "properties": {
                  "code": {
                    "type": "integer",
                    "enum": [
                      0
                    ],
                    "description": "成功状态码，过滤器创建并提交事务后固定为 0。"
                  },
                  "msg": {
                    "type": "string",
                    "enum": [
                      "过滤器添加成功"
                    ],
                    "description": "过滤器记录创建成功后返回的确认消息。"
                  },
                  "data": {
                    "type": "integer",
                    "format": "int64",
                    "minimum": 1,
                    "description": "数据库为新 CC 过滤器生成的唯一 ID。"
                  }
                },
                "additionalProperties": false
              },
              {
                "type": "object",
                "required": [
                  "code",
                  "msg",
                  "data"
                ],
                "properties": {
                  "code": {
                    "type": "string",
                    "enum": [
                      "cc_filter-10",
                      "cc_filter-11",
                      "cc_filter-13",
                      "cc_filter-14",
                      "cc_filter-16",
                      "cc_filter-17",
                      "cc_filter-18",
                      "cc_filter-19",
                      "cc_filter-20",
                      "cc_filter-21",
                      "cc_filter-22",
                      "cc_filter-23",
                      "cc_filter-24",
                      "cc_filter-25",
                      "cc_filter-26",
                      "cc_filter-27",
                      "cc_filter-28",
                      "cc_filter-29",
                      "cc_filter-36",
                      "cc_filter-37",
                      "cc_filter-38",
                      "cc_filter-39",
                      "cc_filter-40",
                      "cc_filter-41",
                      "cc_filter-42",
                      "cc_filter-43",
                      "cc_filter-44",
                      "cc_filter-45",
                      "cc_filter-46",
                      "cc_filter-47",
                      "cc_filter-48",
                      "cc_filter-49",
                      "cc_filter-50",
                      "cc_filter-55",
                      "cc_filter-56",
                      "cc_filter-57",
                      "maintain",
                      "login_required"
                    ],
                    "description": "业务错误码：10 表示创建数量超过站点关联对象配额；11、13、14 表示名称为空、重复或缺失；16 至 18 表示类型为空、无效或缺失；19 至 27 表示统计窗口、总请求上限或单 URI 上限为空、格式错误或缺失；28、29 表示 enable 为空或超出 0/1；36 至 50 表示 URL 鉴权扩展配置缺失或无效，其中 49 表示 internal 超出 0/1；55 至 57 表示普通用户使用管理员专属参数；`maintain` 表示当前禁止写操作，`login_required` 表示认证无效。"
                  },
                  "msg": {
                    "type": "string",
                    "description": "与业务错误码对应的中文配额、字段校验、URL 鉴权、权限、维护状态或认证失败原因。"
                  },
                  "data": {
                    "type": "string",
                    "enum": [
                      ""
                    ],
                    "description": "业务错误时固定为空字符串。"
                  }
                },
                "additionalProperties": false
              }
            ]
          },
          "example": {
            "code": 0,
            "msg": "过滤器添加成功",
            "data": 10021
          }
        }
      }
    }
  },
  "x-python-handler": "site.CCFilterAPI",
  "x-python-route-line": 398,
  "x-audience": "user",
  "x-auth": "user",
  "x-reviewed": true,
  "requestBody": {
    "required": true,
    "content": {
      "application/json": {
        "schema": {
          "type": "object",
          "required": [
            "name",
            "type",
            "within_second",
            "max_req"
          ],
          "properties": {
            "name": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255,
              "description": "过滤器名称；服务端会过滤可执行的 HTML 内容，且要求处理后的名称非空、在所属用户下唯一。"
            },
            "des": {
              "type": "string",
              "maxLength": 255,
              "default": "",
              "description": "过滤器备注；服务端会过滤可执行的 HTML 内容，省略时保存为空字符串。"
            },
            "type": {
              "type": "string",
              "enum": [
                "easy_click_filter",
                "easy_slide_filter",
                "req_rate",
                "302_challenge",
                "browser_verify_auto",
                "slide_filter",
                "captcha_filter",
                "click_filter",
                "url_auth",
                "delay_jump_filter",
                "rotate_filter"
              ],
              "description": "过滤器实现类型，决定达到请求阈值后采用限速、验证、跳转、轮转或 URL 鉴权行为。"
            },
            "within_second": {
              "oneOf": [
                {
                  "type": "integer",
                  "minimum": 0
                },
                {
                  "type": "string",
                  "pattern": "^[0-9]+$"
                }
              ],
              "description": "请求统计窗口的秒数；接受非负整数或仅含十进制数字的字符串，不能为空。"
            },
            "max_req": {
              "oneOf": [
                {
                  "type": "integer",
                  "minimum": 0
                },
                {
                  "type": "string",
                  "pattern": "^[0-9]+$"
                }
              ],
              "description": "在 `within_second` 统计窗口内允许的最大请求数；接受非负整数或仅含十进制数字的字符串，不能为空。"
            },
            "max_req_per_uri": {
              "oneOf": [
                {
                  "type": "integer",
                  "minimum": 0
                },
                {
                  "type": "string",
                  "pattern": "^[0-9]+$"
                }
              ],
              "description": "同一 URI 在统计窗口内允许的最大请求数；`type=req_rate` 时必填且必须是非负整数或十进制数字字符串，其他类型省略或传空值时保存为 0。"
            },
            "extra": {
              "type": "object",
              "additionalProperties": true,
              "description": "过滤器扩展配置。仅 `url_auth` 类型会保存该对象并要求完整的 URL 鉴权字段；其他类型会忽略传入内容并保存为空对象。"
            },
            "uid": {
              "type": "integer",
              "format": "int64",
              "minimum": 1,
              "description": "新过滤器所属用户的 ID；省略时为当前登录用户，仅管理员可指定该字段，否则返回 `cc_filter-56`。"
            },
            "internal": {
              "type": "integer",
              "enum": [
                0,
                1
              ],
              "default": 0,
              "description": "是否创建为系统内置过滤器：1 表示内置，0 表示用户自定义；省略时为 0，传 1 要求管理员身份，否则返回 `cc_filter-57`。"
            },
            "enable": {
              "type": "integer",
              "enum": [
                0,
                1
              ],
              "default": 1,
              "description": "兼容性输入字段，只接受 0 或 1；新增记录最终固定以启用状态 1 保存，即使这里传 0 也不会创建禁用记录。"
            }
          },
          "oneOf": [
            {
              "required": [
                "max_req_per_uri"
              ],
              "properties": {
                "type": {
                  "type": "string",
                  "enum": [
                    "req_rate"
                  ],
                  "description": "请求频率限制类型，要求同时提供单 URI 请求上限。"
                }
              },
              "description": "`req_rate` 过滤器的条件字段。"
            },
            {
              "required": [
                "extra"
              ],
              "properties": {
                "type": {
                  "type": "string",
                  "enum": [
                    "url_auth"
                  ],
                  "description": "URL 鉴权类型，要求同时提供符合所选模式的扩展配置。"
                },
                "extra": {
                  "oneOf": [
                    {
                      "type": "object",
                      "required": [
                        "mode",
                        "key",
                        "sign_name",
                        "time_name",
                        "time_diff",
                        "sign_use_times"
                      ],
                      "properties": {
                        "mode": {
                          "type": "string",
                          "enum": [
                            "TypeA"
                          ],
                          "description": "URL 鉴权模式；TypeA 从独立的时间戳查询参数读取签名时间。"
                        },
                        "key": {
                          "type": "string",
                          "minLength": 16,
                          "maxLength": 32,
                          "description": "计算 URL 签名使用的密钥，长度必须为 16 至 32 个字符。"
                        },
                        "sign_name": {
                          "type": "string",
                          "minLength": 1,
                          "description": "请求 URL 中承载签名值的查询参数名，不能为空。"
                        },
                        "time_name": {
                          "type": "string",
                          "minLength": 1,
                          "description": "TypeA 模式下承载签名时间戳的查询参数名，不能为空。"
                        },
                        "time_diff": {
                          "oneOf": [
                            {
                              "type": "integer",
                              "minimum": 0,
                              "maximum": 3600
                            },
                            {
                              "type": "string",
                              "pattern": "^[0-9]+$"
                            }
                          ],
                          "description": "签名时间与服务端时间允许的最大秒数差，必须为不超过 3600 的非负整数。"
                        },
                        "sign_use_times": {
                          "oneOf": [
                            {
                              "type": "integer",
                              "minimum": 0
                            },
                            {
                              "type": "string",
                              "pattern": "^[0-9]+$"
                            }
                          ],
                          "description": "同一签名允许使用的次数，必须为非负整数或仅含十进制数字的字符串。"
                        }
                      },
                      "additionalProperties": true,
                      "description": "TypeA URL 鉴权扩展配置；未识别的附加键会一并序列化保存。"
                    },
                    {
                      "type": "object",
                      "required": [
                        "mode",
                        "key",
                        "sign_name",
                        "time_diff",
                        "sign_use_times"
                      ],
                      "properties": {
                        "mode": {
                          "type": "string",
                          "enum": [
                            "TypeB"
                          ],
                          "description": "URL 鉴权模式；TypeB 不要求独立的时间戳参数名。"
                        },
                        "key": {
                          "type": "string",
                          "minLength": 16,
                          "maxLength": 32,
                          "description": "计算 URL 签名使用的密钥，长度必须为 16 至 32 个字符。"
                        },
                        "sign_name": {
                          "type": "string",
                          "minLength": 1,
                          "description": "请求 URL 中承载签名值的查询参数名，不能为空。"
                        },
                        "time_diff": {
                          "oneOf": [
                            {
                              "type": "integer",
                              "minimum": 0,
                              "maximum": 3600
                            },
                            {
                              "type": "string",
                              "pattern": "^[0-9]+$"
                            }
                          ],
                          "description": "签名时间与服务端时间允许的最大秒数差，必须为不超过 3600 的非负整数。"
                        },
                        "sign_use_times": {
                          "oneOf": [
                            {
                              "type": "integer",
                              "minimum": 0
                            },
                            {
                              "type": "string",
                              "pattern": "^[0-9]+$"
                            }
                          ],
                          "description": "同一签名允许使用的次数，必须为非负整数或仅含十进制数字的字符串。"
                        }
                      },
                      "additionalProperties": true,
                      "description": "TypeB URL 鉴权扩展配置；未识别的附加键会一并序列化保存。"
                    }
                  ],
                  "description": "根据 `mode` 选择 TypeA 或 TypeB 的 URL 鉴权配置。"
                }
              },
              "description": "`url_auth` 过滤器的条件字段。"
            },
            {
              "properties": {
                "type": {
                  "type": "string",
                  "enum": [
                    "easy_click_filter",
                    "easy_slide_filter",
                    "302_challenge",
                    "browser_verify_auto",
                    "slide_filter",
                    "captcha_filter",
                    "click_filter",
                    "delay_jump_filter",
                    "rotate_filter"
                  ],
                  "description": "无需额外条件字段的验证、跳转或轮转过滤器类型。"
                }
              },
              "description": "除请求频率限制和 URL 鉴权之外的过滤器类型。"
            }
          ],
          "additionalProperties": true,
          "description": "创建 CC 过滤器的 JSON 对象；未识别字段不会参与创建逻辑。"
        },
        "example": {
          "name": "请求频率限制",
          "des": "限制短时间内对同一 URI 的重复请求",
          "type": "req_rate",
          "within_second": 60,
          "max_req": 100,
          "max_req_per_uri": 20
        }
      }
    }
  },
  "parameters": [
    {
      "name": "internal",
      "in": "query",
      "required": false,
      "description": "兼容性权限检查参数。传 1 时要求管理员身份，否则返回 `cc_filter-55`；该查询参数本身不会把新过滤器标记为内置，创建内置过滤器应同时在 JSON 请求体中传 `internal: 1`。",
      "schema": {
        "type": "integer",
        "enum": [
          1
        ]
      },
      "example": 1
    }
  ],
  "x-itecdn-source-reviewed": true,
  "extensions": [
    {
      "key": "x-python-handler",
      "value": "site.CCFilterAPI"
    },
    {
      "key": "x-python-route-line",
      "value": 398
    },
    {
      "key": "x-audience",
      "value": "user"
    },
    {
      "key": "x-auth",
      "value": "user"
    },
    {
      "key": "x-reviewed",
      "value": true
    },
    {
      "key": "x-itecdn-source-reviewed",
      "value": true
    }
  ],
  "method": "post",
  "path": "/v1/cc-filters",
  "servers": [
    {
      "url": "https://master.example.invalid",
      "description": "不可调用的示例地址；复制示例后替换为自己的主控域名。"
    }
  ],
  "securitySchemes": {
    "AccessToken": {
      "type": "apiKey",
      "in": "header",
      "name": "access-token",
      "description": "通过登录接口获得的短期访问令牌。"
    },
    "ApiKey": {
      "type": "apiKey",
      "in": "header",
      "name": "api-key",
      "description": "API Key；必须和 api-secret 同时发送。"
    },
    "ApiSecret": {
      "type": "apiKey",
      "in": "header",
      "name": "api-secret",
      "description": "API Secret；必须和 api-key 同时发送。"
    }
  },
  "jsonRequestBodyExample": {
    "name": "string",
    "des": "",
    "type": "req_rate",
    "within_second": 0,
    "max_req": 0,
    "max_req_per_uri": 0,
    "extra": {},
    "uid": 0,
    "internal": 0,
    "enable": 1
  },
  "info": {
    "title": "itecdn v5 用户 API",
    "version": "5.x",
    "description": "itecdn v5.x Python 主控用户 API。本文档不适用于 v6 或其它实现。"
  },
  "postman": {
    "name": "创建 CC 过滤器",
    "description": {
      "content": "为当前登录用户创建一个 CC 过滤器，创建前会按照当前账号的网站数量和系统配置检查可创建的站点关联对象配额；同一所属用户下过滤器名称不可重复。普通用户只能创建归属于自己的自定义过滤器，管理员可通过请求体指定所属用户或创建系统内置过滤器。`req_rate` 类型必须配置单 URI 请求上限，`url_auth` 类型必须配置 URL 鉴权参数；其他类型的扩展配置会以空对象保存。新增过滤器固定以启用状态和版本 1 写入。",
      "type": "text/plain"
    },
    "url": {
      "path": [
        "v1",
        "cc-filters"
      ],
      "host": [
        "{{baseUrl}}"
      ],
      "query": [
        {
          "disabled": false,
          "description": {
            "content": "兼容性权限检查参数。传 1 时要求管理员身份，否则返回 `cc_filter-55`；该查询参数本身不会把新过滤器标记为内置，创建内置过滤器应同时在 JSON 请求体中传 `internal: 1`。",
            "type": "text/plain"
          },
          "key": "internal",
          "value": ""
        }
      ],
      "variable": []
    },
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "method": "POST",
    "body": {
      "mode": "raw",
      "raw": "",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "auth": {
      "type": "apikey",
      "apikey": [
        {
          "type": "any",
          "value": "access-token",
          "key": "key"
        },
        {
          "type": "any",
          "value": "{{apiKey}}",
          "key": "value"
        },
        {
          "type": "any",
          "value": "header",
          "key": "in"
        }
      ]
    }
  }
}