From 46ae37a4a172186b2465087e96b0cd8132ea646b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Sat, 26 Oct 2024 04:39:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E7=AD=BE=E5=8F=91=E8=AF=81=E4=B9=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 2 +- go.sum | 4 ++-- internal/biz/cert.go | 1 + internal/data/cert.go | 6 ++++++ internal/data/cert_account.go | 7 ++++++- internal/data/website.go | 19 +++++++++++-------- internal/http/request/file.go | 2 +- web/src/views/cert/CertView.vue | 3 ++- web/src/views/website/EditView.vue | 17 ++++++++++++++--- 9 files changed, 44 insertions(+), 17 deletions(-) diff --git a/go.mod b/go.mod index 31a00bdc69..ff2780faa5 100644 --- a/go.mod +++ b/go.mod @@ -130,4 +130,4 @@ require ( modernc.org/sqlite v1.32.0 // indirect ) -replace github.com/mholt/acmez/v2 => github.com/TheTNB/acmez/v2 v2.0.0-20241012163130-5833d84639e0 +replace github.com/mholt/acmez/v2 => github.com/TheTNB/acmez/v2 v2.0.0-20241025203320-cc718c4c870b diff --git a/go.sum b/go.sum index e4ec716432..6ab4a1f3ba 100644 --- a/go.sum +++ b/go.sum @@ -23,8 +23,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/Microsoft/go-winio v0.4.14 h1:+hMXMk01us9KgxGb7ftKQt2Xpf5hH/yky+TDA+qxleU= github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= -github.com/TheTNB/acmez/v2 v2.0.0-20241012163130-5833d84639e0 h1:o66ZhpjXVs7oi3VyiZvlpp9StFFe4KTeklzB/T4s59Q= -github.com/TheTNB/acmez/v2 v2.0.0-20241012163130-5833d84639e0/go.mod h1:pQ1ysaDeGrIMvJ9dfJMk5kJNkn7L2sb3UhyrX6Q91cw= +github.com/TheTNB/acmez/v2 v2.0.0-20241025203320-cc718c4c870b h1:1iVxCglpEJ/kq48YcujkWq8SeOacMuMmuekMmGyOSPA= +github.com/TheTNB/acmez/v2 v2.0.0-20241025203320-cc718c4c870b/go.mod h1:pQ1ysaDeGrIMvJ9dfJMk5kJNkn7L2sb3UhyrX6Q91cw= github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY= github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= github.com/beevik/ntp v1.4.3 h1:PlbTvE5NNy4QHmA4Mg57n7mcFTmr1W1j3gcK7L1lqho= diff --git a/internal/biz/cert.go b/internal/biz/cert.go index 37b25c2da2..c2e283d499 100644 --- a/internal/biz/cert.go +++ b/internal/biz/cert.go @@ -29,6 +29,7 @@ type Cert struct { type CertRepo interface { List(page, limit uint) ([]*Cert, int64, error) Get(id uint) (*Cert, error) + GetByWebsite(WebsiteID uint) (*Cert, error) Create(req *request.CertCreate) (*Cert, error) Update(req *request.CertUpdate) error Delete(id uint) error diff --git a/internal/data/cert.go b/internal/data/cert.go index 88785b2bd8..3fe7ddca5f 100644 --- a/internal/data/cert.go +++ b/internal/data/cert.go @@ -37,6 +37,12 @@ func (r *certRepo) Get(id uint) (*biz.Cert, error) { return cert, err } +func (r *certRepo) GetByWebsite(WebsiteID uint) (*biz.Cert, error) { + cert := new(biz.Cert) + err := app.Orm.Model(&biz.Cert{}).Preload("Website").Preload("Account").Preload("DNS").Where("website_id = ?", WebsiteID).First(cert).Error + return cert, err +} + func (r *certRepo) Create(req *request.CertCreate) (*biz.Cert, error) { cert := &biz.Cert{ AccountID: req.AccountID, diff --git a/internal/data/cert_account.go b/internal/data/cert_account.go index 2cce566c65..feb8cac7e1 100644 --- a/internal/data/cert_account.go +++ b/internal/data/cert_account.go @@ -34,8 +34,13 @@ func (r certAccountRepo) GetDefault(userID uint) (*biz.CertAccount, error) { return nil, err } + account := new(biz.CertAccount) + if err = app.Orm.Model(&biz.CertAccount{}).Where("ca = ?", "googlecn").Where("email = ?", user.Email).First(account).Error; err == nil { + return account, nil + } + req := &request.CertAccountCreate{ - CA: acme.CAGoogleCN, + CA: "googlecn", Email: user.Email, KeyType: string(acme.KeyEC256), } diff --git a/internal/data/website.go b/internal/data/website.go index d0689e4d0d..91160704c1 100644 --- a/internal/data/website.go +++ b/internal/data/website.go @@ -695,15 +695,18 @@ func (r *websiteRepo) ObtainCert(ctx context.Context, id uint) error { } cRepo := NewCertRepo() - newCert, err := cRepo.Create(&request.CertCreate{ - Type: string(acme.KeyEC256), - Domains: website.Domains, - AutoRenew: true, - AccountID: account.ID, - WebsiteID: website.ID, - }) + newCert, err := cRepo.GetByWebsite(website.ID) if err != nil { - return err + newCert, err = cRepo.Create(&request.CertCreate{ + Type: string(acme.KeyEC256), + Domains: website.Domains, + AutoRenew: true, + AccountID: account.ID, + WebsiteID: website.ID, + }) + if err != nil { + return err + } } _, err = cRepo.ObtainAuto(newCert.ID) diff --git a/internal/http/request/file.go b/internal/http/request/file.go index 477236f3bc..dfe5a5d731 100644 --- a/internal/http/request/file.go +++ b/internal/http/request/file.go @@ -22,7 +22,7 @@ type FileCreate struct { type FileSave struct { Path string `form:"path" json:"path" validate:"required"` - Content string `form:"content" json:"content" validate:"required"` + Content string `form:"content" json:"content"` } type FileMove struct { diff --git a/web/src/views/cert/CertView.vue b/web/src/views/cert/CertView.vue index 16ee170a9b..1e894fc0d8 100644 --- a/web/src/views/cert/CertView.vue +++ b/web/src/views/cert/CertView.vue @@ -1,5 +1,6 @@