mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2024-12-13 07:59:08 +08:00
60 lines
1.2 KiB
Go
60 lines
1.2 KiB
Go
package service
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
|
|
"github.com/1Panel-dev/1Panel/agent/app/dto"
|
|
"github.com/1Panel-dev/1Panel/agent/constant"
|
|
)
|
|
|
|
type SettingService struct{}
|
|
|
|
type ISettingService interface {
|
|
GetSettingInfo() (*dto.SettingInfo, error)
|
|
Update(key, value string) error
|
|
}
|
|
|
|
func NewISettingService() ISettingService {
|
|
return &SettingService{}
|
|
}
|
|
|
|
func (u *SettingService) GetSettingInfo() (*dto.SettingInfo, error) {
|
|
setting, err := settingRepo.GetList()
|
|
if err != nil {
|
|
return nil, constant.ErrRecordNotFound
|
|
}
|
|
settingMap := make(map[string]string)
|
|
for _, set := range setting {
|
|
settingMap[set.Key] = set.Value
|
|
}
|
|
var info dto.SettingInfo
|
|
arr, err := json.Marshal(settingMap)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if err := json.Unmarshal(arr, &info); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
info.LocalTime = time.Now().Format("2006-01-02 15:04:05 MST -0700")
|
|
return &info, err
|
|
}
|
|
|
|
func (u *SettingService) Update(key, value string) error {
|
|
switch key {
|
|
case "AppStoreLastModified":
|
|
exist, _ := settingRepo.Get(settingRepo.WithByKey("AppStoreLastModified"))
|
|
if exist.ID == 0 {
|
|
_ = settingRepo.Create("AppStoreLastModified", value)
|
|
return nil
|
|
}
|
|
}
|
|
|
|
if err := settingRepo.Update(key, value); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|