2021-09-26 02:35:02 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
json2 "encoding/json"
|
2022-06-08 10:19:45 +00:00
|
|
|
"time"
|
2021-10-29 10:37:27 +00:00
|
|
|
|
2021-09-27 06:17:36 +00:00
|
|
|
"github.com/IceWhaleTech/CasaOS/model"
|
|
|
|
"github.com/IceWhaleTech/CasaOS/pkg/config"
|
2022-06-29 03:09:58 +00:00
|
|
|
"github.com/IceWhaleTech/CasaOS/pkg/utils/httper"
|
2021-09-26 02:35:02 +00:00
|
|
|
"github.com/tidwall/gjson"
|
|
|
|
)
|
|
|
|
|
2021-11-03 09:07:46 +00:00
|
|
|
type CasaService interface {
|
2022-06-29 03:09:58 +00:00
|
|
|
GetCasaosVersion() model.Version
|
2021-09-26 02:35:02 +00:00
|
|
|
}
|
|
|
|
|
2022-11-29 17:17:14 +00:00
|
|
|
type casaService struct{}
|
2021-09-26 02:35:02 +00:00
|
|
|
|
2022-06-29 03:09:58 +00:00
|
|
|
/**
|
|
|
|
* @description: get remote version
|
|
|
|
* @return {model.Version}
|
|
|
|
*/
|
|
|
|
func (o *casaService) GetCasaosVersion() model.Version {
|
|
|
|
keyName := "casa_version"
|
|
|
|
var dataStr string
|
|
|
|
var version model.Version
|
|
|
|
if result, ok := Cache.Get(keyName); ok {
|
|
|
|
dataStr, ok = result.(string)
|
|
|
|
if ok {
|
|
|
|
data := gjson.Get(dataStr, "data")
|
|
|
|
json2.Unmarshal([]byte(data.String()), &version)
|
|
|
|
return version
|
|
|
|
}
|
|
|
|
}
|
2022-02-17 10:43:25 +00:00
|
|
|
|
2022-06-29 03:09:58 +00:00
|
|
|
v := httper.OasisGet(config.ServerInfo.ServerApi + "/v1/sys/version")
|
|
|
|
data := gjson.Get(v, "data")
|
|
|
|
json2.Unmarshal([]byte(data.String()), &version)
|
2022-02-17 10:43:25 +00:00
|
|
|
|
2022-06-29 03:09:58 +00:00
|
|
|
if len(version.Version) > 0 {
|
|
|
|
Cache.Set(keyName, v, time.Minute*20)
|
|
|
|
}
|
2022-02-17 10:43:25 +00:00
|
|
|
|
2022-06-29 03:09:58 +00:00
|
|
|
return version
|
2022-02-17 10:43:25 +00:00
|
|
|
}
|
|
|
|
|
2022-03-09 08:37:03 +00:00
|
|
|
func NewCasaService() CasaService {
|
2021-11-03 09:07:46 +00:00
|
|
|
return &casaService{}
|
2021-09-26 02:35:02 +00:00
|
|
|
}
|