{
  "openapi": "3.1.0",
  "info": {
    "title": "CloudDrive REST API",
    "version": "0.2.0-preview"
  },
  "security": [
    {
      "OwnerSession": []
    }
  ],
  "paths": {
    "/api/v1/files": {
      "get": {
        "summary": "列出当前管理员的文件",
        "parameters": [
          {
            "name": "prefix",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 120
            }
          },
          {
            "name": "trash",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "0",
                "1"
              ]
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "name": "view",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "folder"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "文件分页",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "items",
                    "nextOffset",
                    "directories",
                    "summary"
                  ],
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/File"
                      }
                    },
                    "nextOffset": {
                      "type": [
                        "integer",
                        "null"
                      ]
                    },
                    "directories": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "summary": {
                      "type": "object",
                      "required": [
                        "files",
                        "bytes"
                      ],
                      "properties": {
                        "files": {
                          "type": "integer"
                        },
                        "bytes": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "post": {
        "summary": "以单次请求上传最多 1 MiB 的文件",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "path",
                  "base64"
                ],
                "properties": {
                  "path": {
                    "type": "string",
                    "maxLength": 512
                  },
                  "base64": {
                    "type": "string",
                    "contentEncoding": "base64",
                    "maxLength": 1398104
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/File"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/files/{id}": {
      "parameters": [
        {
          "$ref": "#/components/parameters/Id"
        }
      ],
      "get": {
        "summary": "读取元数据或下载私有文件",
        "parameters": [
          {
            "name": "download",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "0",
                "1"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "元数据或附件",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/File"
                }
              },
              "application/octet-stream": {}
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "patch": {
        "summary": "移动或重命名文件",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "revision",
                  "path"
                ],
                "properties": {
                  "revision": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "path": {
                    "type": "string",
                    "maxLength": 512
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/File"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "delete": {
        "summary": "移入回收站",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "$ref": "#/components/requestBodies/Revision"
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/File"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "post": {
        "summary": "恢复回收站文件",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "$ref": "#/components/requestBodies/Revision"
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/File"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/shares": {
      "post": {
        "summary": "创建受限密码、期限和授权次数的分享",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "fileId",
                  "password",
                  "expiresAt",
                  "maxDownloads"
                ],
                "properties": {
                  "fileId": {
                    "type": "string"
                  },
                  "password": {
                    "type": "string",
                    "minLength": 8,
                    "maxLength": 256
                  },
                  "expiresAt": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "maxDownloads": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 100
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "创建成功，返回分享 ID"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "get": {
        "summary": "列出管理员已创建的分享",
        "responses": {
          "200": {
            "description": "分享列表及已签发下载次数"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/shares/{id}": {
      "parameters": [
        {
          "$ref": "#/components/parameters/Id"
        }
      ],
      "post": {
        "summary": "核验分享条件并下载附件",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "password"
                ],
                "properties": {
                  "password": {
                    "type": "string",
                    "maxLength": 256
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "附件，计为一次授权签发",
            "content": {
              "application/octet-stream": {}
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "delete": {
        "summary": "撤销分享",
        "responses": {
          "204": {
            "description": "已撤销"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/organize": {
      "post": {
        "summary": "生成整理建议",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "fileId"
                ],
                "properties": {
                  "fileId": {
                    "type": "string"
                  },
                  "mode": {
                    "enum": [
                      "rules",
                      "metadata",
                      "skip"
                    ]
                  },
                  "intent": {
                    "type": "string",
                    "maxLength": 240
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "模型或规则建议"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/uploads/init": {
      "post": {
        "summary": "预留空间并登记待传文件",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "path",
                  "size",
                  "sha256"
                ],
                "properties": {
                  "path": {
                    "type": "string",
                    "maxLength": 512
                  },
                  "size": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 1048576
                  },
                  "sha256": {
                    "type": "string",
                    "pattern": "^[a-f0-9]{64}$"
                  },
                  "provider": {
                    "enum": [
                      "vercel-blob-private",
                      "cnb-oci"
                    ]
                  },
                  "purpose": {
                    "enum": [
                      "personal",
                      "build-artifact",
                      "software-release"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "上传预留"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ]
      }
    },
    "/api/v1/uploads/complete": {
      "post": {
        "summary": "上传正文并完成读回校验",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "id",
                  "base64"
                ],
                "properties": {
                  "id": {
                    "type": "string",
                    "pattern": "^[a-f0-9]{64}$"
                  },
                  "base64": {
                    "type": "string",
                    "contentEncoding": "base64",
                    "maxLength": 1398104
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/File"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/storage/status": {
      "get": {
        "summary": "读取私有索引占用及写入配额状态",
        "responses": {
          "200": {
            "description": "索引统计、配置额度和核查状态"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/tokens": {
      "get": {
        "summary": "列出项目凭据",
        "responses": {
          "200": {
            "description": "成功"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "post": {
        "summary": "创建有时限和作用域的凭据",
        "responses": {
          "201": {
            "description": "成功"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/tokens/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^[A-F0-9]{24}$"
          }
        }
      ],
      "delete": {
        "summary": "撤销凭据",
        "responses": {
          "204": {
            "description": "成功"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/project/files": {
      "get": {
        "summary": "列出项目文件或按 id 下载",
        "responses": {
          "200": {
            "description": "成功"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "security": [
          {
            "ProjectBearer": []
          }
        ]
      },
      "post": {
        "summary": "上传项目文件",
        "responses": {
          "200": {
            "description": "成功"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "security": [
          {
            "ProjectBearer": []
          }
        ]
      },
      "delete": {
        "summary": "将项目文件移入回收站",
        "responses": {
          "default": {
            "$ref": "#/components/responses/Error"
          },
          "204": {
            "description": "成功"
          }
        },
        "security": [
          {
            "ProjectBearer": []
          }
        ]
      }
    },
    "/api/v1/maintenance": {
      "get": {
        "summary": "读取日整理和月度归档报告",
        "responses": {
          "200": {
            "description": "成功"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "post": {
        "summary": "处理变更文件或读回校验",
        "responses": {
          "200": {
            "description": "成功"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/uploads/plan": {
      "post": {
        "summary": "规划上传，返回推荐后端、可执行后端及拒绝原因",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "path",
                  "size"
                ],
                "properties": {
                  "path": {
                    "type": "string",
                    "maxLength": 512
                  },
                  "size": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 100000000000
                  },
                  "purpose": {
                    "enum": [
                      "personal",
                      "build-artifact",
                      "software-release"
                    ]
                  },
                  "useModel": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "模型或规则推荐及上传准入结果"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/recovery": {
      "get": {
        "summary": "读取当前 Git 检查点",
        "responses": {
          "200": {
            "description": "提交 SHA 和索引数量"
          }
        }
      },
      "post": {
        "summary": "校验对象并从 Git 检查点恢复缺失索引",
        "responses": {
          "200": {
            "description": "恢复的对象元数据"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "OwnerSession": {
        "type": "apiKey",
        "in": "cookie",
        "name": "__Host-cd_session"
      },
      "ProjectBearer": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "parameters": {
      "Id": {
        "name": "id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        }
      },
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": true,
        "schema": {
          "type": "string",
          "pattern": "^[0-9a-zA-Z_-]{16,128}$"
        }
      }
    },
    "requestBodies": {
      "Revision": {
        "required": true,
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "required": [
                "revision"
              ],
              "properties": {
                "revision": {
                  "type": "integer",
                  "minimum": 1
                }
              }
            }
          }
        }
      }
    },
    "responses": {
      "File": {
        "description": "文件元数据",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/File"
            }
          }
        }
      },
      "Error": {
        "description": "错误代码",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "required": [
                "error"
              ],
              "properties": {
                "error": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "schemas": {
      "File": {
        "type": "object",
        "required": [
          "id",
          "path",
          "bytes",
          "sha256",
          "visibility",
          "status",
          "revision"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "path": {
            "type": "string"
          },
          "bytes": {
            "type": "integer"
          },
          "sha256": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          },
          "visibility": {
            "const": "Private"
          },
          "status": {
            "enum": [
              "READY",
              "TRASHED"
            ]
          },
          "revision": {
            "type": "integer"
          }
        }
      }
    }
  }
}
