From b6eb9dc1123f8b760a9c7592b7331d39fd2df607 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=9C=E8=8F=AF?= Date: Fri, 28 Apr 2023 08:40:40 +0800 Subject: [PATCH] params --- README.md | 16 ++++++++++------ main.go | 13 ++++++++++++- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index b19b649..2258e8b 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ ai 繪圖服務端(快速重構) - [ ] /api/tasks [#任務詳情](#任務列表) - [ ] /api/models [#模型列表](#模型列表) - [ ] /api/images [#圖片列表](#圖片列表) +- [ ] /api/params [#參數列表](#參數列表) 列表接口-請求方式 Method | URL | Info @@ -24,11 +25,12 @@ POST | /api/{name} | 篩選:創建新對象 * 過濾條件有多個的,複寫query(交集) 詳情接口: -- [ ] /api/tags/{tag_id} [#標籤詳情](#標籤詳情) -- [ ] /api/users/{user_id} [#用戶詳情](#用戶詳情) -- [ ] /api/tasks/{task_id} [#任務詳情](#任務詳情) -- [ ] /api/models/{model_id} [#模型詳情](#模型詳情) -- [ ] /api/images/{image_id} [#圖片詳情](#圖片詳情) +- [ ] /api/tags/{tag_id} [#標籤詳情](#標籤詳情) +- [ ] /api/users/{user_id} [#用戶詳情](#用戶詳情) +- [ ] /api/tasks/{task_id} [#任務詳情](#任務詳情) +- [ ] /api/models/{model_id} [#模型詳情](#模型詳情) +- [ ] /api/images/{image_id} [#圖片詳情](#圖片詳情) +- [ ] /api/params/{params_id} [#參數詳情](#參數詳情) 詳情接口-請求方式: Method | URL | Info @@ -42,7 +44,6 @@ WS | /api/{name}/{item_id} | Websocket 連接對象 * GET查詢以外的操作都必須在headers中攜帶token驗證身份權限 * GET查詢私有模型也必須登錄, 否則不會被展示 - 對象模型: ```go type ListView struct { @@ -111,6 +112,9 @@ type User struct { CreatedAt string `json:"created_at"` UpdatedAt string `json:"updated_at"` } + +type Param struct { +} ``` ```javascript //// TODO diff --git a/main.go b/main.go index b932173..47b4edb 100644 --- a/main.go +++ b/main.go @@ -44,10 +44,21 @@ func main() { r.HandleFunc("/api/tasks/{id}", tasks_item_patch).Methods("PATCH") r.HandleFunc("/api/tasks/{id}", tasks_item_delete).Methods("DELETE") + r.HandleFunc("/api/params/model", models_params_get).Methods("GET") + log.Println("Web Server is running on http://localhost:8080") http.ListenAndServe(":8080", r) } +func models_params_get(w http.ResponseWriter, r *http.Request) { + params := make(map[string]interface{}) + params["type"] = []string{"lora", "ckp", "hyper", "ti"} + params["status"] = []string{"pending", "running", "finished", "failed"} + params["base_model"] = []string{"SD1.5", "SD2"} + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Write(ToJSON(params)) +} + func models_get(w http.ResponseWriter, r *http.Request) { var listview models.ListView listview.Page = ParamInt(r.URL.Query().Get("page"), 1) @@ -154,7 +165,7 @@ func images_get(w http.ResponseWriter, r *http.Request) { listview.Total = models.CountImages() listview.Next = listview.Page*listview.PageSize < listview.Total w.Header().Set("Content-Type", "application/json; charset=utf-8") - w.Write(ToJSON(listview)) + w.Write(listview.ToJSON()) } func images_post(w http.ResponseWriter, r *http.Request) {