color
This commit is contained in:
		@@ -101,9 +101,34 @@ func SessionsItemPatch(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
 | 
			
		||||
// 刪除會話
 | 
			
		||||
func SessionsItemDelete(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
	session := models.Session{ID: mux.Vars(r)["id"]}
 | 
			
		||||
	// 需要先驗證身份才能執行刪除操作
 | 
			
		||||
 | 
			
		||||
	// 從Cookie中獲取session_id
 | 
			
		||||
	cookie, err := r.Cookie("session_id")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		w.WriteHeader(http.StatusUnauthorized)
 | 
			
		||||
		w.Write([]byte("401 - 未登錄"))
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 獲取當前session
 | 
			
		||||
	session := models.Session{ID: cookie.Value}
 | 
			
		||||
	session.Get()
 | 
			
		||||
	session.Delete()
 | 
			
		||||
 | 
			
		||||
	// 獲取當前用戶
 | 
			
		||||
	user := models.User{ID: session.UserID}
 | 
			
		||||
	user.Get()
 | 
			
		||||
 | 
			
		||||
	sessionx := models.Session{ID: mux.Vars(r)["id"]}
 | 
			
		||||
	sessionx.Get()
 | 
			
		||||
 | 
			
		||||
	if user.ID != sessionx.UserID {
 | 
			
		||||
		w.WriteHeader(http.StatusUnauthorized)
 | 
			
		||||
		w.Write([]byte("401 - 沒有權限"))
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	sessionx.Delete()
 | 
			
		||||
	w.Header().Set("Content-Type", "application/json; charset=utf-8")
 | 
			
		||||
	w.Write(utils.ToJSON(session))
 | 
			
		||||
	w.Write(utils.ToJSON(sessionx))
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -56,13 +56,13 @@ func LogComponent(startTime int64, r *http.Request) {
 | 
			
		||||
	color := "\033[1;32m%d\033[0m"
 | 
			
		||||
	if ms > 800 {
 | 
			
		||||
		color = "\033[1;31m%dms\033[0m" // 紅色加重
 | 
			
		||||
	} else if ms > 500 {
 | 
			
		||||
	} else if ms > 1000 {
 | 
			
		||||
		color = "\033[1;33m%dms\033[0m" // 黃色加重
 | 
			
		||||
	} else if ms > 300 {
 | 
			
		||||
		color = "\033[1;32m%dms\033[0m" // 綠色加重
 | 
			
		||||
	} else if ms > 200 {
 | 
			
		||||
		color = "\033[1;34m%dms\033[0m" // 藍色加重
 | 
			
		||||
	} else if ms > 100 {
 | 
			
		||||
		color = "\033[1;32m%dms\033[0m" // 綠色加重
 | 
			
		||||
	} else if ms > 10 {
 | 
			
		||||
		color = "\033[1;34m%dms\033[0m" // 藍色加重
 | 
			
		||||
	} else if ms > 1 {
 | 
			
		||||
		color = "\033[1;35m%dms\033[0m" // 紫色加重
 | 
			
		||||
	} else {
 | 
			
		||||
		color = "\033[1;36m%dms\033[0m" // 黑色加重
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user