Skip to content

Commit

Permalink
Remount if the configuration file already exists (#877)
Browse files Browse the repository at this point in the history
  • Loading branch information
LinkLeong authored Feb 9, 2023
1 parent b331c48 commit fbfcc2c
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 26 deletions.
1 change: 1 addition & 0 deletions build/sysroot/usr/lib/systemd/system/casaos.service
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[Unit]
After=casaos-message-bus.service
After=rclone.service
ConditionFileNotEmpty=/etc/casaos/casaos.conf
Description=CasaOS Main Service

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ require (
go.uber.org/zap v1.24.0
golang.org/x/crypto v0.5.0
golang.org/x/oauth2 v0.3.0
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
gorm.io/gorm v1.24.3
gotest.tools v2.2.0+incompatible
)
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ golang.org/x/oauth2 v0.3.0 h1:6l90koy8/LaBLmLu8jpHeHexzMwEita0zFfYlggy2F8=
golang.org/x/oauth2 v0.3.0/go.mod h1:rQrIauxkUhJ6CuwEXwymO2/eh4xz2ZWF1nBkcxS+tGk=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
1 change: 0 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ func main() {
route.V2APIPath,
route.V2DocPath,
route.V3FilePath,
route.V4DirPath,
}
for _, apiPath := range routers {
err = service.MyService.Gateway().CreateRoute(&model.Route{
Expand Down
7 changes: 4 additions & 3 deletions route/periodical.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ func SendAllHardwareStatusBySocket() {

body["sys_net"] = newNet
systemTempMap := service.MyService.Notify().GetSystemTempMap()
for k, v := range systemTempMap {
body[k] = v
}
systemTempMap.Range(func(key, value interface{}) bool {
body[key.(string)] = value
return true
})
service.MyService.Notify().SendNotify("casaos:system:utilization", body)
}

Expand Down
16 changes: 4 additions & 12 deletions route/v1/recover.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,8 @@ func GetRecoverStorage(c *gin.Context) {
username = fileutil.NameAccumulation(username, "/mnt")
dataMap, _ := service.MyService.Storage().GetConfigByName(username)
if len(dataMap) > 0 {
c.String(200, `<p>The same configuration has been added</p><script>window.close()</script>`)
service.MyService.Storage().CheckAndMountByName(username)
notify["status"] = "warn"
notify["message"] = "The same configuration has been added"
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
return
service.MyService.Storage().UnmountStorage("/mnt/" + username)
service.MyService.Storage().DeleteConfigByName(username)
}
dmap := make(map[string]string)
dmap["client_id"] = add.ClientID
Expand Down Expand Up @@ -115,12 +111,8 @@ func GetRecoverStorage(c *gin.Context) {
username = fileutil.NameAccumulation(username, "/mnt")
dataMap, _ := service.MyService.Storage().GetConfigByName(username)
if len(dataMap) > 0 {
c.String(200, `<p>The same configuration has been added</p><script>window.close()</script>`)
service.MyService.Storage().CheckAndMountByName(username)
notify["status"] = "warn"
notify["message"] = "The same configuration has been added"
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
return
service.MyService.Storage().UnmountStorage("/mnt/" + username)
service.MyService.Storage().DeleteConfigByName(username)
}
dmap := make(map[string]string)
dmap["client_id"] = add.AppKey
Expand Down
8 changes: 5 additions & 3 deletions route/v1/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,11 @@ func GetSystemUtilization(c *gin.Context) {
}

data["net"] = newNet
for k, v := range service.MyService.Notify().GetSystemTempMap() {
data[k] = v
}
systemMap := service.MyService.Notify().GetSystemTempMap()
systemMap.Range(func(key, value interface{}) bool {
data[key.(string)] = value
return true
})
c.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: data})
}

Expand Down
4 changes: 2 additions & 2 deletions route/v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ func InitV2Router() http.Handler {

e.Use(echo_middleware.JWTWithConfig(echo_middleware.JWTConfig{
Skipper: func(c echo.Context) bool {
// return c.RealIP() == "::1" || c.RealIP() == "127.0.0.1"
return true
return c.RealIP() == "::1" || c.RealIP() == "127.0.0.1"
//return true
},
ParseTokenFunc: func(token string, c echo.Context) (interface{}, error) {
claims, code := jwt.Validate(token)
Expand Down
12 changes: 7 additions & 5 deletions service/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/IceWhaleTech/CasaOS/service/model"
"github.com/IceWhaleTech/CasaOS/types"
"go.uber.org/zap"
"golang.org/x/sync/syncmap"

socketio "github.com/googollee/go-socket.io"
"github.com/gorilla/websocket"
Expand All @@ -36,17 +37,18 @@ type NotifyServer interface {
//SendInstallAppBySocket(app notifyCommon.Application)
SendNotify(name string, message map[string]interface{})
SettingSystemTempData(message map[string]interface{})
GetSystemTempMap() map[string]interface{}
GetSystemTempMap() syncmap.Map
}

type notifyServer struct {
db *gorm.DB
SystemTempMap map[string]interface{}
SystemTempMap syncmap.Map //[string]interface{}
}

func (i *notifyServer) SettingSystemTempData(message map[string]interface{}) {
for k, v := range message {
i.SystemTempMap[k] = v
i.SystemTempMap.Store(k, v)
//i.SystemTempMap[k] = v
}
}

Expand Down Expand Up @@ -340,10 +342,10 @@ func SendMeg() {
// }

// }
func (i *notifyServer) GetSystemTempMap() map[string]interface{} {
func (i *notifyServer) GetSystemTempMap() syncmap.Map {
return i.SystemTempMap
}

func NewNotifyService(db *gorm.DB) NotifyServer {
return &notifyServer{db: db, SystemTempMap: make(map[string]interface{})}
return &notifyServer{db: db, SystemTempMap: syncmap.Map{}}
}

0 comments on commit fbfcc2c

Please sign in to comment.