This commit is contained in:
2023-05-14 09:33:41 +08:00
parent acb4839912
commit d328b31210
4 changed files with 34 additions and 4 deletions

View File

@@ -10,6 +10,7 @@ import (
"main/utils"
"net/http"
"strconv"
"time"
"github.com/gorilla/mux"
"github.com/gorilla/websocket"
@@ -134,19 +135,25 @@ func ModelItemPatch(w http.ResponseWriter, r *http.Request) {
if model_new.Status != "" && model_new.Status != model.Status {
model.Status = model_new.Status
// 如果狀態被改變爲 ready, 將模型發送到訓練隊列
//if model.Status == "ready" {
// model.SendToTrain()
//}
if model.Status == "ready" {
model.Status = "training"
go model.Train()
}
}
if model_new.Image != "" && model_new.Image != model.Image {
model.Image = model_new.Image
}
// 更新時間
model.UpdatedAt = time.Now().Format("2006-01-02 15:04:05")
// 執行更新
if err := configs.ORMDB().Save(&model).Error; err != nil {
log.Println(err)
return
}
// 返回更新後的數據
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.Write(utils.ToJSON(model))
}

View File

@@ -76,7 +76,7 @@ func SessionsPost(w http.ResponseWriter, r *http.Request) {
}
// 創建會話(生成一個不重複的 uuid 作爲 sid)
session := &models.Session{ID: uuid.New().String(), UserID: user.ID}
session := &models.Session{ID: uuid.New().String(), UserID: user.ID, UserAgent: r.UserAgent(), IP: r.RemoteAddr}
if err := configs.ORMDB().Create(session).Error; err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("500 - Internal Server Error"))