# ai 繪圖 - [ ] 注册用户前验证手机号或者邮箱是否已经存在 - [ ] 使用验证码登录功能同时创建账户 用戶: ```go type User struct { ID int `json:"id" gorm:"primary_key"` Name string `json:"name"` Email string `json:"email" gorm:"unique;not null"` Password string `json:"-"` Slat string `json:"-"` Admin bool `json:"admin"` CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"` UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"` } ``` - [x] GET [/api/users](/api/users) 用戶列表 - [x] POST [/api/users](/api/users) 創建用戶 `{email:'', password:'', name:''}` - [x] GET [/api/users](/api/users) 查詢指定用戶 - [x] PATCH [/api/users/{id}](/api/users/{id}) 修改指定用戶 - [x] DELETE [/api/users/{id}](/api/users/{id}) 刪除指定用戶 會話: ```go type Session struct { ID string `json:"id" gorm:"primary_key"` IP string `json:"ip"` UserID int `json:"user_id"` UserAgent string `json:"user_agent"` CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"` UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"` } ``` - [x] GET [/api/sessions](/api/sessions) 會話列表 - [x] POST [/api/sessions](/api/sessions) 登錄賬戶(創建會話) `{email:'', password:''}` - [x] GET [/api/sessions/{id}](/api/sessions/{id}) 查詢會話詳情 - [x] PATCH [/api/sessions/{id}](/api/sessions/{id}) 修改會話狀態 - [x] DELETE [/api/sessions/{id}](/api/sessions/{id}) 註銷登錄(刪除指定會話) 數據集: ```go type Dataset struct { ID int `json:"id" gorm:"primary_key"` Name string `json:"name"` Info string `json:"info"` Images ImageList `json:"images"` UserID int `json:"user_id"` CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"` UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"` } type ImageList []string // image URL ``` - [x] GET [/api/datasets](/api/datasets) 數據集列表 - [x] POST [/api/datasets](/api/datasets) 創建數據集 `{images:['https://oss..']}` - [x] GET [/api/datasets/{id}](/api/datasets/{id}) 查詢指定數據集 - [x] PATCH [/api/datasets/{id}](/api/datasets/{id}) 修改指定數據集 - [x] DELETE [/api/datasets/{id}](/api/datasets/{id}) 刪除指定數據集 標籤: ```go type Tag struct { ID int `json:"id" gorm:"primary_key"` Name string `json:"name"` CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"` UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"` } ``` - [x] GET [/api/tags](/api/tags) 標籤列表(全部) - [x] POST [/api/tags](/api/tags) 創建標籤 `{name:''}` - [x] GET [/api/tags/{id}](/api/tags/{id}) 標籤詳情 - [x] PATCH [/api/tags/{id}](/api/tags/{id}) 修改標籤 - [x] DELETE [/api/tags/{id}](/api/tags/{id}) 刪除標籤 模型: ```go type Model struct { ID int `json:"id" gorm:"primary_key"` // 模型ID Name string `json:"name"` // 模型名稱 Info string `json:"info"` // 模型描述 Type string `json:"type"` // 模型類型(lora|ckp|hyper|ti) TriggerWords string `json:"trigger_words"` // 觸發詞 BaseModel string `json:"base_model"` // 基礎模型(SD1.5|SD2) ModelPath string `json:"model_path"` // 模型路徑(實際存放在服務器上的路徑) Status string `json:"status" default:"initial"` // (initial|ready|waiting|running|success|error) Progress int `json:"progress"` // (0-100) Image string `json:"image"` // 封面圖片實際地址 Hash string `json:"hash"` // 模型哈希值 Epochs int `json:"epochs"` // 訓練步數 LearningRate float32 `json:"learning_rate"` // 學習率(0.000005) Tags TagList `json:"tags"` // 模型標籤(標籤名數組) UserID int `json:"user_id"` // 模型的所有者 DatasetID int `json:"dataset_id"` // 模型所使用的數據集ID ServerID string `json:"server_id"` // 模型所在服務器(訓練機或推理機) CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"` UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"` } ``` - [x] GET [/api/models](/api/models) 模型列表(全部) - [x] GET [/api/models?user_id=xxx](/api/models?user_id=xxx) 模型列表(指定用戶的) - [x] GET [/api/models?tag=動物](/api/models?tag=xxx) 模型列表(指定標籤的) - [x] GET [/api/models?sort=hot](/api/models?sort=hot) 圖片列表(熱門) - [x] GET [/api/models?sort=createdAt](/api/models?sort=createdAt) 圖片列表(最新) - [x] GET [/api/models?search=布穀鳥](/api/models?search=布穀鳥) 圖片列表(關鍵詞搜索) - [x] POST [/api/models](/api/models) 創建並訓練新模型(dataset_id 爲必填) - [x] PATCH [/api/models/{id}](/api/models/{id}) 修改指定模型 - [x] DELETE [/api/models/{id}](/api/models/{id}) 刪除指定模型 圖像: ```go type Image struct { ID int `json:"id" gorm:"primary_key"` Name string `json:"name"` Hash string `json:"hash"` Path string `json:"path"` Type string `json:"type"` Size int `json:"size"` Width int `json:"width"` Height int `json:"height"` Prompt string `json:"prompt"` Format string `json:"format"` NegativePrompt string `json:"negative_prompt"` NumInferenceSteps int `json:"num_inference_steps"` // Number of inference steps (minimum: 1; maximum: 500) GuidanceScale float32 `json:"guidance_scale"` // Scale for classifier-free guidance (minimum: 1; maximum: 20) Scheduler string `json:"scheduler"` // (DDIM|K_EULER|DPMSolverMultistep|K_EULER_ANCESTRAL|PNDM|KLMS) Seed int `json:"seed"` // Random seed (minimum: 0; maximum: 2147483647) FromImage string `json:"from_image"` // Image to start from UserID int `json:"user_id"` CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"` UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"` } ``` - [x] GET [/api/images](/api/images) 圖片列表(全部) - [x] GET [/api/images?user_id=xxx](/api/images?user_id=xxx) 圖片列表(指定用戶的) - [x] GET [/api/images?tag=xxx](/api/images?tag=xxx) 圖片列表(指定標籤的) - [x] POST [/api/images](/api/images) 上傳圖片(單張) - [x] DELETE [/api/images/{id}](/api/images/{id}) 刪除指定圖像 ```bash # 上傳圖片示例 response=$(curl -X POST -H "Content-Type: multipart/form-data" -F "file=@./data/test.jpeg" -b "session_id=$session_id" -s -w "%{http_code}" http://localhost:8080/api/images) message "$response" "上傳圖片" true ``` 提供webp生成服务 ```javascript // GET /img/{id}-{version}-{width}-{height}-{fit}.{format} // @id: 取图片ID // @version: 取 hash 前 6 位 // @width: 所需宽度 1x 2x 3x 倍图直接输入尺寸 // @height: 所需高度 1x 2x 3x 倍图直接输入尺寸 // @fit: 裁切方式 cover contain fill auto ``` 參數: ```go type Param struct { // 字段不固定 } ``` - [x] GET [/api/params](/api/params) 參數列表(全部參數) - [x] GET [/api/params/model](/api/params/model) 模型參數 賬戶: ```go type Account struct { ID int `json:"id"` Name string `json:"name"` Email string `json:"email"` Admin bool `json:"admin"` SessionID string `json:"session_id"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` } ``` - [x] GET [/api/account](/api/account) 當前賬戶信息 - [x] GET [/api/account](/api/account) 當前賬戶信息 服務器: ```go type Server struct { ID int `json:"id" gorm:"primary_key"` Name string `json:"name"` Type string `json:"type"` // (訓練|推理) IP string `json:"ip"` Port int `json:"port"` Status string `json:"status"` // (異常|初始化|閒置|就緒|工作中|關閉中) UserName string `json:"username"` Password string `json:"password"` Models []map[string]interface{} `json:"models" gorm:"-"` // 數據庫不必保存 CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"` UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"` } ``` - [x] GET [/api/servers](/api/servers) 服務器列表 列表模型: ```go type ListView struct { Page int `json:"page"` // 当前页码 PageSize int `json:"page_size"` // 分頁大小 Total int `json:"total"` // 數據總量 Next bool `json:"next"` // 可否翻頁 List []interface{} `json:"list"` // 數據列表 } ``` ----------------------------------------------------------- 列表接口-請求方式 Method | URL | Info -------|--------------------------------|------------------ GET | /api/{name} | 分頁:顺序查询 GET | /api/{name}?page=1&pageSize=20 | 分頁:页码和數量 GET | /api/{name}?user_id=1234 | 篩選:按用戶 GET | /api/{name}?tag=xxx | 篩選:按標籤 GET | /api/{name}?public=true | 篩選:公開狀態(true|false) POST | /api/{name} | 篩選:創建新對象 * 選取條件有多個的,以逗號分隔(並集) * 過濾條件有多個的,複寫query(交集) 詳情接口-請求方式: Method | URL | Info -------|--------------------------------|------------------ GET | /api/{name}/{item_id} | 獲取對象詳情 PATCH | /api/{name}/{item_id} | 修改對象字段 DELETE | /api/{name}/{item_id} | 刪除對象 WS | /api/{name}/{item_id} | Websocket 連接對象 * GET查詢以外的操作都必須在headers中攜帶token驗證身份權限 * GET查詢私有模型也必須登錄, 否則不會被展示