diff --git a/go.mod b/go.mod index 4571a5e..7a60d2c 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.16 require ( github.com/Curtis-Milo/nat-type-identifier-go v0.0.0-20220215191915-18d42168c63d - github.com/IceWhaleTech/CasaOS-Common v0.3.9-0.20221124035157-905ff67a1bd0 + github.com/IceWhaleTech/CasaOS-Common v0.3.9-0.20221124043453-88f2175065c8 github.com/IceWhaleTech/CasaOS-Gateway v0.3.6 github.com/ambelovsky/go-structs v1.1.0 // indirect github.com/ambelovsky/gosf v0.0.0-20201109201340-237aea4d6109 diff --git a/go.sum b/go.sum index 93c79fe..3a5ef9f 100644 --- a/go.sum +++ b/go.sum @@ -69,8 +69,8 @@ github.com/Curtis-Milo/nat-type-identifier-go v0.0.0-20220215191915-18d42168c63d github.com/Curtis-Milo/nat-type-identifier-go v0.0.0-20220215191915-18d42168c63d/go.mod h1:lW9x+yEjqKdPbE3+cf2fGPJXCw/hChX3Omi9QHTLFsQ= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= github.com/IceWhaleTech/CasaOS-Common v0.0.0-20220901034123-ca130f6b5ce9/go.mod h1:2MiivEMzvh41codhEKUcn46WK3Ffesop/04qa9jsvQk= -github.com/IceWhaleTech/CasaOS-Common v0.3.9-0.20221124035157-905ff67a1bd0 h1:MrugHqlCrfBMS3ns7qlbNkBhrGBLWXgWI4t07CH4v2E= -github.com/IceWhaleTech/CasaOS-Common v0.3.9-0.20221124035157-905ff67a1bd0/go.mod h1:xcemiRsXcs1zrmQxYMyExDjZ7UHYwkJqYE71IDIV0xA= +github.com/IceWhaleTech/CasaOS-Common v0.3.9-0.20221124043453-88f2175065c8 h1:u5gl4V07tjZNB0W7Vca98Nredt67Dz6i+uy3JryJZos= +github.com/IceWhaleTech/CasaOS-Common v0.3.9-0.20221124043453-88f2175065c8/go.mod h1:xcemiRsXcs1zrmQxYMyExDjZ7UHYwkJqYE71IDIV0xA= github.com/IceWhaleTech/CasaOS-Gateway v0.3.6 h1:2tQQo85+jzbbjqIsKKn77QlAA73bc7vZsVCFvWnK4mg= github.com/IceWhaleTech/CasaOS-Gateway v0.3.6/go.mod h1:hnZwGUzcOyiufMpVO7l3gu2gAm6Ws4TY4Nlj3kMshXA= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= diff --git a/model/notify/application.go b/model/notify/application.go deleted file mode 100644 index 439de9f..0000000 --- a/model/notify/application.go +++ /dev/null @@ -1,21 +0,0 @@ -/* - * @Author: LinkLeong link@icewhale.com - * @Date: 2022-05-27 15:01:58 - * @LastEditors: LinkLeong - * @LastEditTime: 2022-05-31 14:51:21 - * @FilePath: /CasaOS/model/notify/application.go - * @Description: - * @Website: https://www.casaos.io - * Copyright (c) 2022 by icewhale, All Rights Reserved. - */ -package notify - -type Application struct { - Name string `json:"name"` - State string `json:"state"` - Type string `json:"type"` - Icon string `json:"icon"` - Message string `json:"message"` - Finished bool `json:"finished"` - Success bool `json:"success"` -} diff --git a/route/v1/notify.go b/route/v1/notify.go index fefa769..100a49e 100644 --- a/route/v1/notify.go +++ b/route/v1/notify.go @@ -3,8 +3,8 @@ package v1 import ( "net/http" + "github.com/IceWhaleTech/CasaOS-Common/model/notify" "github.com/IceWhaleTech/CasaOS/model" - "github.com/IceWhaleTech/CasaOS/model/notify" "github.com/IceWhaleTech/CasaOS/pkg/utils/common_err" "github.com/IceWhaleTech/CasaOS/service" "github.com/gin-gonic/gin" diff --git a/service/notify.go b/service/notify.go index 5e31ebe..1571f28 100644 --- a/service/notify.go +++ b/service/notify.go @@ -5,6 +5,7 @@ import ( "fmt" "time" + notifyCommon "github.com/IceWhaleTech/CasaOS-Common/model/notify" model2 "github.com/IceWhaleTech/CasaOS/model" "github.com/IceWhaleTech/CasaOS/model/notify" "github.com/IceWhaleTech/CasaOS/service/model" @@ -15,24 +16,26 @@ import ( "gorm.io/gorm" ) -var NotifyMsg chan notify.Message -var ClientCount int = 0 +var ( + NotifyMsg chan notify.Message + ClientCount int +) type NotifyServer interface { GetLog(id string) model.AppNotify AddLog(log model.AppNotify) UpdateLog(log model.AppNotify) - UpdateLogByCustomId(log model.AppNotify) + UpdateLogByCustomID(log model.AppNotify) DelLog(id string) GetList(c int) (list []model.AppNotify) MarkRead(id string, state int) // SendText(m model.AppNotify) - SendUninstallAppBySocket(app notify.Application) + SendUninstallAppBySocket(app notifyCommon.Application) SendNetInfoBySocket(netList []model2.IOCountersStat) SendCPUInfoBySocket(cpu map[string]interface{}) SendMemInfoBySocket(mem map[string]interface{}) SendFileOperateNotify(nowSend bool) - SendInstallAppBySocket(app notify.Application) + SendInstallAppBySocket(app notifyCommon.Application) SendAllHardwareStatusBySocket(mem map[string]interface{}, cpu map[string]interface{}, netList []model2.IOCountersStat) SendStorageBySocket(message notify.StorageMessage) SendNotify(path string, message map[string]interface{}) @@ -62,7 +65,6 @@ func (i *notifyServer) SendNotify(path string, message map[string]interface{}) { notify.Msg = msg NotifyMsg <- notify - } func (i *notifyServer) SendStorageBySocket(message notify.StorageMessage) { @@ -80,8 +82,8 @@ func (i *notifyServer) SendStorageBySocket(message notify.StorageMessage) { NotifyMsg <- notify } -func (i *notifyServer) SendAllHardwareStatusBySocket(mem map[string]interface{}, cpu map[string]interface{}, netList []model2.IOCountersStat) { +func (i *notifyServer) SendAllHardwareStatusBySocket(mem map[string]interface{}, cpu map[string]interface{}, netList []model2.IOCountersStat) { body := make(map[string]interface{}) body["sys_mem"] = mem @@ -104,12 +106,10 @@ func (i *notifyServer) SendAllHardwareStatusBySocket(mem map[string]interface{}, notify.Msg = msg NotifyMsg <- notify - } // Send periodic broadcast messages func (i *notifyServer) SendFileOperateNotify(nowSend bool) { - if nowSend { len := 0 @@ -259,7 +259,6 @@ func (i *notifyServer) SendFileOperateNotify(nowSend bool) { time.Sleep(time.Second * 3) } } - } func (i *notifyServer) SendMemInfoBySocket(mem map[string]interface{}) { @@ -278,7 +277,7 @@ func (i *notifyServer) SendMemInfoBySocket(mem map[string]interface{}) { NotifyMsg <- notify } -func (i *notifyServer) SendInstallAppBySocket(app notify.Application) { +func (i *notifyServer) SendInstallAppBySocket(app notifyCommon.Application) { body := make(map[string]interface{}) body["data"] = app @@ -309,6 +308,7 @@ func (i *notifyServer) SendCPUInfoBySocket(cpu map[string]interface{}) { NotifyMsg <- notify } + func (i *notifyServer) SendNetInfoBySocket(netList []model2.IOCountersStat) { body := make(map[string]interface{}) body["data"] = netList @@ -325,7 +325,7 @@ func (i *notifyServer) SendNetInfoBySocket(netList []model2.IOCountersStat) { NotifyMsg <- notify } -func (i *notifyServer) SendUninstallAppBySocket(app notify.Application) { +func (i *notifyServer) SendUninstallAppBySocket(app notifyCommon.Application) { body := make(map[string]interface{}) body["data"] = app @@ -358,17 +358,20 @@ func (i *notifyServer) AddLog(log model.AppNotify) { func (i *notifyServer) UpdateLog(log model.AppNotify) { i.db.Save(&log) } -func (i *notifyServer) UpdateLogByCustomId(log model.AppNotify) { + +func (i *notifyServer) UpdateLogByCustomID(log model.AppNotify) { if len(log.CustomId) == 0 { return } i.db.Model(&model.AppNotify{}).Select("*").Where("custom_id = ? ", log.CustomId).Updates(log) } + func (i *notifyServer) GetLog(id string) model.AppNotify { var log model.AppNotify i.db.Where("custom_id = ? ", id).First(&log) return log } + func (i *notifyServer) MarkRead(id string, state int) { if id == "0" { i.db.Model(&model.AppNotify{}).Where("1 = ?", 1).Update("state", state) @@ -376,6 +379,7 @@ func (i *notifyServer) MarkRead(id string, state int) { } i.db.Model(&model.AppNotify{}).Where("id = ? ", id).Update("state", state) } + func (i *notifyServer) DelLog(id string) { var log model.AppNotify i.db.Where("custom_id = ?", id).Delete(&log) @@ -444,10 +448,9 @@ func SendMeg() { // } func (i *notifyServer) GetSystemTempMap() map[string]interface{} { - return i.SystemTempMap - } + func NewNotifyService(db *gorm.DB) NotifyServer { return ¬ifyServer{db: db, SystemTempMap: make(map[string]interface{})} }