118 lines
4.5 KiB
Go
118 lines
4.5 KiB
Go
package schema
|
||
|
||
import (
|
||
"net/url"
|
||
"octopus/pkg/tools"
|
||
"time"
|
||
|
||
"github.com/gofiber/fiber/v2"
|
||
)
|
||
|
||
type DocFolder struct {
|
||
ID string `json:"id" oai:"description=文件夹ID"`
|
||
IsDeletable bool `json:"is_deletable" oai:"description=文件夹是否允许被删除"`
|
||
IsEditable bool `json:"is_editable" oai:"description=文件夹是否允许被修改"`
|
||
CreatedAt time.Time `json:"created_at" oai:"description=创建时间"`
|
||
UpdatedAt time.Time `json:"updated_at" oai:"description=更新时间"`
|
||
}
|
||
|
||
type DocFolderID struct {
|
||
ID string `path:"id" oai:"description=文件夹ID"`
|
||
}
|
||
|
||
type CreateDocFolder struct {
|
||
Name string `json:"name" validate:"required" oai:"description=文件夹名称"`
|
||
ParentID string `json:"parent_id" oai:"description=父文件夹ID,空表示在根路径创建"`
|
||
}
|
||
|
||
type UpdateDocFolder struct {
|
||
Name *string `json:"name" oai:"description=修改文件夹名称"`
|
||
ParentID *string `json:"parent_id" oai:"description=修改文件夹父级ID"`
|
||
}
|
||
|
||
type GetDocFolderTree struct {
|
||
ParentID *string `query:"parent_id" oai:"description=父文件夹ID,空表示获取根路径"`
|
||
}
|
||
|
||
type DocFolderWithChildren struct {
|
||
ID string `json:"id" oai:"description=文件夹ID,**根文件夹无ID**"`
|
||
IsDeletable bool `json:"is_deletable" oai:"description=文件夹是否允许被删除"`
|
||
IsEditable bool `json:"is_editable" oai:"description=文件夹是否允许被修改"`
|
||
CreatedAt time.Time `json:"created_at" oai:"description=创建时间"`
|
||
UpdatedAt time.Time `json:"updated_at" oai:"description=更新时间"`
|
||
Children []*DocFolderWithChildren `json:"children" oai:"description=子文件夹"`
|
||
}
|
||
|
||
type Doc struct {
|
||
ID string `json:"id" oai:"description=文档ID"`
|
||
Folder *DocFolder `json:"folder" oai:"description=归属文件夹信息"`
|
||
PresignedURL *url.URL `json:"presigned_url" oai:"description=文档预签名下载URL(临时下载URL)"`
|
||
IsDeletable bool `json:"is_deletable" oai:"description=文件夹是否允许被删除"`
|
||
IsEditable bool `json:"is_editable" oai:"description=文件夹是否允许被修改"`
|
||
UploadedAt time.Time `json:"uploaded_at" oai:"description=上传时间"`
|
||
CreatedAt time.Time `json:"created_at" oai:"description=创建时间"`
|
||
UpdatedAt time.Time `json:"updated_at" oai:"description=更新时间"`
|
||
}
|
||
|
||
type DocList struct {
|
||
Items []*Doc `json:"items" oai:"description=文档列表"`
|
||
Total int64 `json:"total" oai:"description=文档总数"`
|
||
}
|
||
|
||
type DocID struct {
|
||
ID string `path:"id" oai:"description=文档ID"`
|
||
}
|
||
|
||
type CreateDoc struct {
|
||
Name string `json:"name" validate:"required" oai:"description=文档名称"`
|
||
ObjectName string `json:"object_name" validate:"required" oai:"description=对象存储中对应的文档对象名称"`
|
||
FolderID string `json:"folder_id" validate:"required" oai:"description=归属文件夹ID"`
|
||
}
|
||
|
||
type UpdateDoc struct {
|
||
Name *string `json:"name" oai:"description=更新文档名称"`
|
||
FolderID *string `json:"folder_id" oai:"description=更新归属文件夹ID"`
|
||
}
|
||
|
||
type ListDocQuery struct {
|
||
PageableQuery
|
||
SortableQuery
|
||
FolderIDs *[]string `query:"folder_ids" oai:"description=筛选归属文件夹ID"`
|
||
}
|
||
|
||
type DocsBatchDelete struct {
|
||
IDs []string `json:"ids" validate:"required" oai:"description=批量选择文件ID列表"`
|
||
}
|
||
|
||
type DocsBatchUpdate struct {
|
||
IDs []string `json:"ids" validate:"required" oai:"description=批量选择文件ID列表"`
|
||
FolderID string `json:"folder_id" validate:"required" oai:"description=更新归属文件夹ID"`
|
||
}
|
||
|
||
type DocActionResult struct {
|
||
ID string `json:"id" oai:"description=文档ID"`
|
||
Success bool `json:"success" oai:"description=操作是否成功"`
|
||
Message *string `json:"message,omitempty" oai:"description=操作失败信息"`
|
||
}
|
||
|
||
type DocsBatchResults []DocActionResult
|
||
|
||
func (q *ListDocQuery) Validate() error {
|
||
sortable := tools.NewSet("uploaded_at")
|
||
for _, s := range q.GetOrderField() {
|
||
if !sortable.Has(s.Field) {
|
||
return fiber.NewError(fiber.StatusBadRequest, "unsupported order field")
|
||
}
|
||
}
|
||
return nil
|
||
}
|
||
|
||
type CreateUploadURL struct {
|
||
FileName string `query:"file_name" validate:"required" oai:"description=上传文件名"`
|
||
}
|
||
|
||
type UploadURL struct {
|
||
URL url.URL `json:"url" oai:"description=生成的预签名上传URL"`
|
||
ObjectName string `json:"object_name" oai:"description=上传文件名"`
|
||
}
|