From f91d2962edfb654da8aa6a223f9ae8ce31ef8411 Mon Sep 17 00:00:00 2001 From: pupilcc Date: Wed, 10 Jan 2024 01:51:30 +0800 Subject: [PATCH] feat: checked cert exist --- internal/service/ssl_service.go | 2 +- web/ssl.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/service/ssl_service.go b/internal/service/ssl_service.go index bb56f67..ffbb0fa 100644 --- a/internal/service/ssl_service.go +++ b/internal/service/ssl_service.go @@ -21,7 +21,7 @@ func AddCert(name string, certFile *multipart.FileHeader, keyFile *multipart.Fil if certs != nil { for _, cert := range certs { if cert.Name == name { - return fmt.Errorf("cert %s already exist", name) + return fmt.Errorf("certificate %s already exist", name) } } } diff --git a/web/ssl.go b/web/ssl.go index 3c154fc..bb30001 100644 --- a/web/ssl.go +++ b/web/ssl.go @@ -90,6 +90,15 @@ func generate(c echo.Context) error { return err } + certs := service.GetCerts() + if certs != nil { + for _, cert := range certs { + if cert.Name == certCommand.Domain { + return fmt.Errorf("certificate %s already exist", certCommand.Domain) + } + } + } + id := util.GenerateID() err := os.MkdirAll(service.CertPath, 0755) @@ -111,5 +120,6 @@ func generate(c echo.Context) error { return err } + _ = c.JSON(http.StatusOK, response.Message(certCommand.Domain+" Certificate generated successfully.")) return nil }