From 64405fba3df03889909b38f1e2a4662ec5de41ff Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Mon, 19 Aug 2024 18:30:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=BB=9F=E4=B8=80=E6=97=B6=E5=8C=BA?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E6=96=B9=E6=B3=95=20(#6175)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/v1/cronjob.go | 2 +- backend/app/api/v1/monitor.go | 2 +- backend/app/repo/backup.go | 2 +- backend/app/service/clam.go | 4 ++-- backend/app/service/container_volume.go | 2 +- backend/app/service/ssh.go | 2 +- backend/cron/cron.go | 4 ++-- backend/cron/job/ssl.go | 9 +++++---- backend/cron/job/website.go | 7 ++++--- backend/middleware/password_expired.go | 2 +- backend/utils/common/common.go | 7 ------- frontend/src/views/toolbox/device/time-zone/index.vue | 2 ++ 12 files changed, 21 insertions(+), 24 deletions(-) diff --git a/backend/app/api/v1/cronjob.go b/backend/app/api/v1/cronjob.go index 181a28cd7..2e54c3794 100644 --- a/backend/app/api/v1/cronjob.go +++ b/backend/app/api/v1/cronjob.go @@ -72,7 +72,7 @@ func (b *BaseApi) SearchJobRecords(c *gin.Context) { return } - loc, _ := time.LoadLocation(common.LoadTimeZone()) + loc, _ := time.LoadLocation(common.LoadTimeZoneByCmd()) req.StartTime = req.StartTime.In(loc) req.EndTime = req.EndTime.In(loc) diff --git a/backend/app/api/v1/monitor.go b/backend/app/api/v1/monitor.go index 0f7a6e767..cfb7fe743 100644 --- a/backend/app/api/v1/monitor.go +++ b/backend/app/api/v1/monitor.go @@ -28,7 +28,7 @@ func (b *BaseApi) LoadMonitor(c *gin.Context) { return } - loc, _ := time.LoadLocation(common.LoadTimeZone()) + loc, _ := time.LoadLocation(common.LoadTimeZoneByCmd()) req.StartTime = req.StartTime.In(loc) req.EndTime = req.EndTime.In(loc) diff --git a/backend/app/repo/backup.go b/backend/app/repo/backup.go index 19aa09271..57fe6ac82 100644 --- a/backend/app/repo/backup.go +++ b/backend/app/repo/backup.go @@ -48,7 +48,7 @@ func (u *BackupRepo) ListRecord(opts ...DBOption) ([]model.BackupRecord, error) for _, opt := range opts { db = opt(db) } - err := db.Debug().Find(&users).Error + err := db.Find(&users).Error return users, err } diff --git a/backend/app/service/clam.go b/backend/app/service/clam.go index 5b685f5c4..d30f76efb 100644 --- a/backend/app/service/clam.go +++ b/backend/app/service/clam.go @@ -140,7 +140,7 @@ func (c *ClamService) SearchWithPage(req dto.SearchClamWithPage) (int64, interfa item.LastHandleDate = "-" datas = append(datas, item) } - nyc, _ := time.LoadLocation(common.LoadTimeZone()) + nyc, _ := time.LoadLocation(common.LoadTimeZoneByCmd()) for i := 0; i < len(datas); i++ { logPaths := loadFileByName(datas[i].Name) sort.Slice(logPaths, func(i, j int) bool { @@ -323,7 +323,7 @@ func (c *ClamService) LoadRecords(req dto.ClamLogSearch) (int64, interface{}, er } var filterFiles []string - nyc, _ := time.LoadLocation(common.LoadTimeZone()) + nyc, _ := time.LoadLocation(common.LoadTimeZoneByCmd()) for _, item := range logPaths { t1, err := time.ParseInLocation(constant.DateTimeSlimLayout, item, nyc) if err != nil { diff --git a/backend/app/service/container_volume.go b/backend/app/service/container_volume.go index daaa49b4c..b065f89f3 100644 --- a/backend/app/service/container_volume.go +++ b/backend/app/service/container_volume.go @@ -52,7 +52,7 @@ func (u *ContainerService) PageVolume(req dto.SearchWithPage) (int64, interface{ records = list.Volumes[start:end] } - nyc, _ := time.LoadLocation(common.LoadTimeZone()) + nyc, _ := time.LoadLocation(common.LoadTimeZoneByCmd()) for _, item := range records { tag := make([]string, 0) for _, val := range item.Labels { diff --git a/backend/app/service/ssh.go b/backend/app/service/ssh.go index 1f51b4701..4b062c957 100644 --- a/backend/app/service/ssh.go +++ b/backend/app/service/ssh.go @@ -312,7 +312,7 @@ func (u *SSHService) LoadLog(req dto.SearchSSHLog) (*dto.SSHLog, error) { showCountFrom := (req.Page - 1) * req.PageSize showCountTo := req.Page * req.PageSize - nyc, _ := time.LoadLocation(common.LoadTimeZone()) + nyc, _ := time.LoadLocation(common.LoadTimeZoneByCmd()) qqWry, err := qqwry.NewQQwry() if err != nil { global.LOG.Errorf("load qqwry datas failed: %s", err) diff --git a/backend/cron/cron.go b/backend/cron/cron.go index ec9f6d9d5..e3c01c04b 100644 --- a/backend/cron/cron.go +++ b/backend/cron/cron.go @@ -17,14 +17,14 @@ import ( ) func Run() { - nyc, _ := time.LoadLocation(common.LoadTimeZone()) + nyc, _ := time.LoadLocation(common.LoadTimeZoneByCmd()) global.Cron = cron.New(cron.WithLocation(nyc), cron.WithChain(cron.Recover(cron.DefaultLogger)), cron.WithChain(cron.DelayIfStillRunning(cron.DefaultLogger))) var ( interval model.Setting status model.Setting ) - syncBeforeStart() + go syncBeforeStart() if err := global.DB.Where("key = ?", "MonitorStatus").Find(&status).Error; err != nil { global.LOG.Errorf("load monitor status from db failed, err: %v", err) } diff --git a/backend/cron/job/ssl.go b/backend/cron/job/ssl.go index 374d45664..8a4797ff7 100644 --- a/backend/cron/job/ssl.go +++ b/backend/cron/job/ssl.go @@ -1,6 +1,10 @@ package job import ( + "path" + "strings" + "time" + "github.com/1Panel-dev/1Panel/backend/app/dto/request" "github.com/1Panel-dev/1Panel/backend/app/repo" "github.com/1Panel-dev/1Panel/backend/app/service" @@ -8,9 +12,6 @@ import ( "github.com/1Panel-dev/1Panel/backend/global" "github.com/1Panel-dev/1Panel/backend/utils/common" "github.com/1Panel-dev/1Panel/backend/utils/files" - "path" - "strings" - "time" ) type ssl struct { @@ -25,7 +26,7 @@ func (ssl *ssl) Run() { sslRepo := repo.NewISSLRepo() sslService := service.NewIWebsiteSSLService() sslList, _ := sslRepo.List() - nyc, _ := time.LoadLocation(common.LoadTimeZone()) + nyc, _ := time.LoadLocation(common.LoadTimeZoneByCmd()) global.LOG.Info("The scheduled certificate update task is currently in progress ...") now := time.Now().Add(10 * time.Second) for _, s := range sslList { diff --git a/backend/cron/job/website.go b/backend/cron/job/website.go index 4eb91373b..cfd5961d0 100644 --- a/backend/cron/job/website.go +++ b/backend/cron/job/website.go @@ -1,6 +1,9 @@ package job import ( + "sync" + "time" + "github.com/1Panel-dev/1Panel/backend/app/dto/request" "github.com/1Panel-dev/1Panel/backend/app/model" "github.com/1Panel-dev/1Panel/backend/app/repo" @@ -8,8 +11,6 @@ import ( "github.com/1Panel-dev/1Panel/backend/constant" "github.com/1Panel-dev/1Panel/backend/global" "github.com/1Panel-dev/1Panel/backend/utils/common" - "sync" - "time" ) type website struct{} @@ -19,7 +20,7 @@ func NewWebsiteJob() *website { } func (w *website) Run() { - nyc, _ := time.LoadLocation(common.LoadTimeZone()) + nyc, _ := time.LoadLocation(common.LoadTimeZoneByCmd()) websites, _ := repo.NewIWebsiteRepo().List() global.LOG.Info("Website scheduled task in progress ...") now := time.Now().Add(10 * time.Minute) diff --git a/backend/middleware/password_expired.go b/backend/middleware/password_expired.go index d917f43f1..90c3c4d7a 100644 --- a/backend/middleware/password_expired.go +++ b/backend/middleware/password_expired.go @@ -30,7 +30,7 @@ func PasswordExpired() gin.HandlerFunc { helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypePasswordExpired, err) return } - loc, _ := time.LoadLocation(common.LoadTimeZone()) + loc, _ := time.LoadLocation(common.LoadTimeZoneByCmd()) expiredTime, err := time.ParseInLocation(constant.DateTimeLayout, extime.Value, loc) if err != nil { helper.ErrorWithDetail(c, constant.CodePasswordExpired, constant.ErrTypePasswordExpired, err) diff --git a/backend/utils/common/common.go b/backend/utils/common/common.go index d0def7382..75e6c36fc 100644 --- a/backend/utils/common/common.go +++ b/backend/utils/common/common.go @@ -256,13 +256,6 @@ func LoadSizeUnit2F(value float64) string { return fmt.Sprintf("%.2f", value) } -func LoadTimeZone() string { - loc := time.Now().Location() - if _, err := time.LoadLocation(loc.String()); err != nil { - return "Asia/Shanghai" - } - return loc.String() -} func LoadTimeZoneByCmd() string { loc := time.Now().Location().String() if _, err := time.LoadLocation(loc); err != nil { diff --git a/frontend/src/views/toolbox/device/time-zone/index.vue b/frontend/src/views/toolbox/device/time-zone/index.vue index 2dc3107e3..5209045b5 100644 --- a/frontend/src/views/toolbox/device/time-zone/index.vue +++ b/frontend/src/views/toolbox/device/time-zone/index.vue @@ -131,6 +131,8 @@ const onSave = async (formEl: FormInstance | undefined) => { }) .catch(() => { loading.value = false; + let href = window.location.href; + window.open(href, '_self'); }); }); });