diff --git a/README.md b/README.md index 6ef660e..c7cbade 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ ai 繪圖服務端(快速重構) 列表接口: + - [ ] /api/tags [#標籤詳情](#標籤列表) - [ ] /api/users [#用戶詳情](#用戶列表) - [ ] /api/tasks [#任務詳情](#任務列表) @@ -16,6 +17,7 @@ ai 繪圖服務端(快速重構) - [ ] /api/params [#參數列表](#參數列表) 列表接口-請求方式 + Method | URL | Info -------|--------------------------------|------------------ GET | /api/{name} | 分頁:顺序查询 @@ -29,6 +31,7 @@ POST | /api/{name} | 篩選:創建新對象 * 過濾條件有多個的,複寫query(交集) 詳情接口: + - [ ] /api/tags/{tag_id} [#標籤詳情](#標籤詳情) - [ ] /api/users/{user_id} [#用戶詳情](#用戶詳情) - [ ] /api/tasks/{task_id} [#任務詳情](#任務詳情) @@ -37,6 +40,7 @@ POST | /api/{name} | 篩選:創建新對象 - [ ] /api/params/{params_id} [#參數詳情](#參數詳情) 詳情接口-請求方式: + Method | URL | Info -------|--------------------------------|------------------ GET | /api/{name}/{item_id} | 獲取對象詳情 @@ -65,7 +69,7 @@ type Model struct { TriggerWords string `json:"trigger_words"` // 觸發詞 BaseModel string `json:"base_model"` // (SD1.5|SD2) ModelPath string `json:"model_path"` // 模型路徑 - Status string `json:"status"` // (waiting|running|success|error) + Status string `json:"status"` // (initial|ready|waiting|running|success|error) Progress int `json:"progress"` // (0-100) Image string `json:"image"` // 封面圖片實際地址 Tags string `json:"tags"` @@ -78,7 +82,7 @@ type Task struct { ID int `json:"id"` Name string `json:"name"` Type string `json:"type"` // 任務類型(訓練|推理) - Status string `json:"status"` // 任務狀態(waiting|running|success|error) + Status string `json:"status"` // 任務狀態(initial|ready|waiting|running|success|error) Progress int `json:"progress"` // 任務進度(0-100) CreatedAt string `json:"created_at"` UpdatedAt string `json:"updated_at"` @@ -264,7 +268,6 @@ POST | /api/models | 創建一個模型 * 如果未登錄, 返回的結果將過濾掉無權限查看的內容 * 如果已登錄, 返回的結果將包含私有的 - POST /api/models ```javascript // 發送數據 @@ -306,9 +309,15 @@ PATCH /api/models/{model_id} ```javascript { name: 'xxx', // 修改模型名稱 + status: 'ready', // (initial|ready|waiting|running|success|error) } ``` * 修改指定字段, 只傳遞需要修改的字段 +* status 初始默認爲 'initial', 修改爲 'ready' 即就緒狀態, 服務器將爲此任務自動排期 +* 當模型訓練任務被加入等待隊列時, 其狀態自動變更爲 'waiting' +* 當模型訓練任務被執行時, 其狀態自動變更爲 'running', 並開始更新進度條 Progress +* 當模型訓練完成時狀態自動變更爲'success', 失敗時爲'error' +* 訓練中的模型將被鎖定, 無法修改刪除等操作 DELETE /api/models/{model_id} * 刪除指定模型 diff --git a/go.mod b/go.mod index 0e5c960..538582e 100644 --- a/go.mod +++ b/go.mod @@ -8,4 +8,5 @@ require ( github.com/gorilla/mux v1.8.0 github.com/gorilla/websocket v1.5.0 github.com/mattn/go-sqlite3 v1.14.16 + github.com/russross/blackfriday v1.6.0 ) diff --git a/go.sum b/go.sum index f7da4ca..76cf8d1 100644 --- a/go.sum +++ b/go.sum @@ -8,3 +8,5 @@ github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWm github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y= github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= +github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww= +github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY= diff --git a/main.go b/main.go index a24ca23..3a86ace 100644 --- a/main.go +++ b/main.go @@ -1,16 +1,17 @@ package main import ( + "io/ioutil" "log" "net/http" "runtime" - "text/template" "time" "main/routers" "main/utils" "github.com/gorilla/mux" + "github.com/russross/blackfriday" ) func main() { @@ -35,8 +36,15 @@ func main() { // 設定路由 r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - t, _ := template.ParseFiles("templates/index.html") - t.Execute(w, nil) + // 從本地讀取Markdown文件 + input, err := ioutil.ReadFile("./README.md") + if err != nil { + log.Println(err) + return + } + //output := blackfriday.MarkdownBasic(input) + output := blackfriday.Markdown(input, blackfriday.HtmlRenderer(0, "", ""), blackfriday.EXTENSION_TABLES|blackfriday.EXTENSION_FENCED_CODE|blackfriday.EXTENSION_AUTOLINK) + w.Write(output) }) r.HandleFunc("/api/models", routers.ModelsGet).Methods("GET") r.HandleFunc("/api/models", routers.ModelsPost).Methods("POST") diff --git a/models/Model.go b/models/Model.go index 318b9d4..8b3bbf5 100644 --- a/models/Model.go +++ b/models/Model.go @@ -12,7 +12,7 @@ type Model struct { TriggerWords string `json:"trigger_words"` // 觸發詞 BaseModel string `json:"base_model"` // (SD1.5|SD2) ModelPath string `json:"model_path"` // 模型路徑 - Status string `json:"status"` // (waiting|running|success|error) + Status string `json:"status"` // (initial|ready|waiting|running|success|error) Progress int `json:"progress"` // (0-100) Image string `json:"image"` // 封面圖片實際地址 Tags string `json:"tags"` diff --git a/models/Task.go b/models/Task.go index 380459f..b316ca5 100644 --- a/models/Task.go +++ b/models/Task.go @@ -9,7 +9,7 @@ type Task struct { ID int `json:"id"` Name string `json:"name"` Type string `json:"type"` // 任務類型(訓練|推理) - Status string `json:"status"` // (waiting|running|success|error) + Status string `json:"status"` // (initial|ready|waiting|running|success|error) Progress int `json:"progress"` // (0-100) CreatedAt string `json:"created_at"` UpdatedAt string `json:"updated_at"` diff --git a/templates/index.html b/templates/index.html deleted file mode 100644 index 69e55d8..0000000 --- a/templates/index.html +++ /dev/null @@ -1,26 +0,0 @@ - - - - - Home - - -

Home

-

Hi, {{ .Name }}!

- - - - -