ua
This commit is contained in:
		@@ -1,6 +1,7 @@
 | 
				
			|||||||
package models
 | 
					package models
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
	"main/configs"
 | 
						"main/configs"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -24,6 +25,26 @@ func init() {
 | 
				
			|||||||
	configs.ORMDB().AutoMigrate(&Model{})
 | 
						configs.ORMDB().AutoMigrate(&Model{})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (model *Model) Train() (err error) {
 | 
				
			||||||
 | 
						if model.Type == "lora" {
 | 
				
			||||||
 | 
							fmt.Println("lora")
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if model.Type == "ckp" {
 | 
				
			||||||
 | 
							fmt.Println("ckp")
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if model.Type == "hyper" {
 | 
				
			||||||
 | 
							fmt.Println("hyper")
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if model.Type == "ti" {
 | 
				
			||||||
 | 
							fmt.Println("ti")
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//func (model *Model) SendToTrain() error {
 | 
					//func (model *Model) SendToTrain() error {
 | 
				
			||||||
//	db, err := configs.GetDB()
 | 
					//	db, err := configs.GetDB()
 | 
				
			||||||
//	if err != nil {
 | 
					//	if err != nil {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,7 +6,9 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
type Session struct {
 | 
					type Session struct {
 | 
				
			||||||
	ID        string `json:"id" gorm:"primary_key"`
 | 
						ID        string `json:"id" gorm:"primary_key"`
 | 
				
			||||||
 | 
						IP        string `json:"ip"`
 | 
				
			||||||
	UserID    int    `json:"user_id"`
 | 
						UserID    int    `json:"user_id"`
 | 
				
			||||||
 | 
						UserAgent string `json:"user_agent"`
 | 
				
			||||||
	CreatedAt string `json:"created_at"`
 | 
						CreatedAt string `json:"created_at"`
 | 
				
			||||||
	UpdatedAt string `json:"updated_at"`
 | 
						UpdatedAt string `json:"updated_at"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,6 +10,7 @@ import (
 | 
				
			|||||||
	"main/utils"
 | 
						"main/utils"
 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
	"strconv"
 | 
						"strconv"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/gorilla/mux"
 | 
						"github.com/gorilla/mux"
 | 
				
			||||||
	"github.com/gorilla/websocket"
 | 
						"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 {
 | 
						if model_new.Status != "" && model_new.Status != model.Status {
 | 
				
			||||||
		model.Status = model_new.Status
 | 
							model.Status = model_new.Status
 | 
				
			||||||
		// 如果狀態被改變爲 ready, 將模型發送到訓練隊列
 | 
							// 如果狀態被改變爲 ready, 將模型發送到訓練隊列
 | 
				
			||||||
		//if model.Status == "ready" {
 | 
							if model.Status == "ready" {
 | 
				
			||||||
		//	model.SendToTrain()
 | 
								model.Status = "training"
 | 
				
			||||||
		//}
 | 
								go model.Train()
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if model_new.Image != "" && model_new.Image != model.Image {
 | 
						if model_new.Image != "" && model_new.Image != model.Image {
 | 
				
			||||||
		model.Image = model_new.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 {
 | 
						if err := configs.ORMDB().Save(&model).Error; err != nil {
 | 
				
			||||||
		log.Println(err)
 | 
							log.Println(err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 返回更新後的數據
 | 
				
			||||||
	w.Header().Set("Content-Type", "application/json; charset=utf-8")
 | 
						w.Header().Set("Content-Type", "application/json; charset=utf-8")
 | 
				
			||||||
	w.Write(utils.ToJSON(model))
 | 
						w.Write(utils.ToJSON(model))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -76,7 +76,7 @@ func SessionsPost(w http.ResponseWriter, r *http.Request) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 創建會話(生成一個不重複的 uuid 作爲 sid)
 | 
						// 創建會話(生成一個不重複的 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 {
 | 
						if err := configs.ORMDB().Create(session).Error; err != nil {
 | 
				
			||||||
		w.WriteHeader(http.StatusInternalServerError)
 | 
							w.WriteHeader(http.StatusInternalServerError)
 | 
				
			||||||
		w.Write([]byte("500 - Internal Server Error"))
 | 
							w.Write([]byte("500 - Internal Server Error"))
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user