From fd875feef390dbd00d67bcfb93f3e5b1689923f7 Mon Sep 17 00:00:00 2001 From: Fu Diwei Date: Fri, 16 May 2025 18:57:39 +0800 Subject: [PATCH] feat: support 1panel v2 --- internal/deployer/providers.go | 2 + internal/domain/access.go | 1 + .../1panel-console/1panel_console.go | 18 +++++--- .../1panel-console/1panel_console_test.go | 5 +++ .../providers/1panel-site/1panel_site.go | 29 +++++++----- .../providers/1panel-site/1panel_site_test.go | 5 +++ .../providers/1panel-ssl/1panel_ssl.go | 20 ++++++--- .../providers/1panel-ssl/1panel_ssl_test.go | 9 +++- internal/pkg/sdk3rd/1panel/client.go | 20 ++++++--- migrations/1747389600_upgrade.go | 44 +++++++++++++++++++ .../access/AccessForm1PanelConfig.tsx | 8 +++- ui/src/domain/access.ts | 1 + ui/src/i18n/locales/en/nls.access.json | 6 ++- ui/src/i18n/locales/en/nls.provider.json | 4 +- .../i18n/locales/en/nls.workflow.nodes.json | 4 +- ui/src/i18n/locales/zh/nls.access.json | 6 ++- ui/src/i18n/locales/zh/nls.provider.json | 4 +- .../i18n/locales/zh/nls.workflow.nodes.json | 2 +- 18 files changed, 143 insertions(+), 45 deletions(-) create mode 100644 migrations/1747389600_upgrade.go diff --git a/internal/deployer/providers.go b/internal/deployer/providers.go index d69b05b7..79fa88c3 100644 --- a/internal/deployer/providers.go +++ b/internal/deployer/providers.go @@ -111,6 +111,7 @@ func createDeployerProvider(options *deployerProviderOptions) (deployer.Deployer case domain.DeploymentProviderType1PanelConsole: deployer, err := p1PanelConsole.NewDeployer(&p1PanelConsole.DeployerConfig{ ApiUrl: access.ApiUrl, + ApiVersion: access.ApiVersion, ApiKey: access.ApiKey, AllowInsecureConnections: access.AllowInsecureConnections, AutoRestart: maputil.GetBool(options.ProviderExtendedConfig, "autoRestart"), @@ -120,6 +121,7 @@ func createDeployerProvider(options *deployerProviderOptions) (deployer.Deployer case domain.DeploymentProviderType1PanelSite: deployer, err := p1PanelSite.NewDeployer(&p1PanelSite.DeployerConfig{ ApiUrl: access.ApiUrl, + ApiVersion: access.ApiVersion, ApiKey: access.ApiKey, AllowInsecureConnections: access.AllowInsecureConnections, ResourceType: p1PanelSite.ResourceType(maputil.GetOrDefaultString(options.ProviderExtendedConfig, "resourceType", string(p1PanelSite.RESOURCE_TYPE_WEBSITE))), diff --git a/internal/domain/access.go b/internal/domain/access.go index e27d290a..d08ea658 100644 --- a/internal/domain/access.go +++ b/internal/domain/access.go @@ -17,6 +17,7 @@ type Access struct { type AccessConfigFor1Panel struct { ApiUrl string `json:"apiUrl"` + ApiVersion string `json:"apiVersion"` ApiKey string `json:"apiKey"` AllowInsecureConnections bool `json:"allowInsecureConnections,omitempty"` } diff --git a/internal/pkg/core/deployer/providers/1panel-console/1panel_console.go b/internal/pkg/core/deployer/providers/1panel-console/1panel_console.go index 069e01f9..98073585 100644 --- a/internal/pkg/core/deployer/providers/1panel-console/1panel_console.go +++ b/internal/pkg/core/deployer/providers/1panel-console/1panel_console.go @@ -9,12 +9,14 @@ import ( "net/url" "github.com/usual2970/certimate/internal/pkg/core/deployer" - opsdk "github.com/usual2970/certimate/internal/pkg/sdk3rd/1panel" + onepanelsdk "github.com/usual2970/certimate/internal/pkg/sdk3rd/1panel" ) type DeployerConfig struct { // 1Panel 地址。 ApiUrl string `json:"apiUrl"` + // 1Panel 版本。 + ApiVersion string `json:"apiVersion"` // 1Panel 接口密钥。 ApiKey string `json:"apiKey"` // 是否允许不安全的连接。 @@ -26,7 +28,7 @@ type DeployerConfig struct { type DeployerProvider struct { config *DeployerConfig logger *slog.Logger - sdkClient *opsdk.Client + sdkClient *onepanelsdk.Client } var _ deployer.Deployer = (*DeployerProvider)(nil) @@ -36,7 +38,7 @@ func NewDeployer(config *DeployerConfig) (*DeployerProvider, error) { panic("config is nil") } - client, err := createSdkClient(config.ApiUrl, config.ApiKey, config.AllowInsecureConnections) + client, err := createSdkClient(config.ApiUrl, config.ApiVersion, config.ApiKey, config.AllowInsecureConnections) if err != nil { return nil, fmt.Errorf("failed to create sdk client: %w", err) } @@ -59,7 +61,7 @@ func (d *DeployerProvider) WithLogger(logger *slog.Logger) deployer.Deployer { func (d *DeployerProvider) Deploy(ctx context.Context, certPEM string, privkeyPEM string) (*deployer.DeployResult, error) { // 设置面板 SSL 证书 - updateSystemSSLReq := &opsdk.UpdateSystemSSLRequest{ + updateSystemSSLReq := &onepanelsdk.UpdateSystemSSLRequest{ Cert: certPEM, Key: privkeyPEM, SSL: "enable", @@ -79,16 +81,20 @@ func (d *DeployerProvider) Deploy(ctx context.Context, certPEM string, privkeyPE return &deployer.DeployResult{}, nil } -func createSdkClient(apiUrl, apiKey string, skipTlsVerify bool) (*opsdk.Client, error) { +func createSdkClient(apiUrl, apiVersion, apiKey string, skipTlsVerify bool) (*onepanelsdk.Client, error) { if _, err := url.Parse(apiUrl); err != nil { return nil, errors.New("invalid 1panel api url") } + if apiVersion == "" { + return nil, errors.New("invalid 1panel api version") + } + if apiKey == "" { return nil, errors.New("invalid 1panel api key") } - client := opsdk.NewClient(apiUrl, apiKey) + client := onepanelsdk.NewClient(apiUrl, apiVersion, apiKey) if skipTlsVerify { client.WithTLSConfig(&tls.Config{InsecureSkipVerify: true}) } diff --git a/internal/pkg/core/deployer/providers/1panel-console/1panel_console_test.go b/internal/pkg/core/deployer/providers/1panel-console/1panel_console_test.go index abec586c..88bf961a 100644 --- a/internal/pkg/core/deployer/providers/1panel-console/1panel_console_test.go +++ b/internal/pkg/core/deployer/providers/1panel-console/1panel_console_test.go @@ -15,6 +15,7 @@ var ( fInputCertPath string fInputKeyPath string fApiUrl string + fApiVersion string fApiKey string ) @@ -24,6 +25,7 @@ func init() { flag.StringVar(&fInputCertPath, argsPrefix+"INPUTCERTPATH", "", "") flag.StringVar(&fInputKeyPath, argsPrefix+"INPUTKEYPATH", "", "") flag.StringVar(&fApiUrl, argsPrefix+"APIURL", "", "") + flag.StringVar(&fApiVersion, argsPrefix+"APIVERSION", "v1", "") flag.StringVar(&fApiKey, argsPrefix+"APIKEY", "", "") } @@ -34,6 +36,7 @@ Shell command to run this test: --CERTIMATE_DEPLOYER_1PANELCONSOLE_INPUTCERTPATH="/path/to/your-input-cert.pem" \ --CERTIMATE_DEPLOYER_1PANELCONSOLE_INPUTKEYPATH="/path/to/your-input-key.pem" \ --CERTIMATE_DEPLOYER_1PANELCONSOLE_APIURL="http://127.0.0.1:20410" \ + --CERTIMATE_DEPLOYER_1PANELCONSOLE_APIVERSION="v1" \ --CERTIMATE_DEPLOYER_1PANELCONSOLE_APIKEY="your-api-key" */ func TestDeploy(t *testing.T) { @@ -45,11 +48,13 @@ func TestDeploy(t *testing.T) { fmt.Sprintf("INPUTCERTPATH: %v", fInputCertPath), fmt.Sprintf("INPUTKEYPATH: %v", fInputKeyPath), fmt.Sprintf("APIURL: %v", fApiUrl), + fmt.Sprintf("APIVERSION: %v", fApiVersion), fmt.Sprintf("APIKEY: %v", fApiKey), }, "\n")) deployer, err := provider.NewDeployer(&provider.DeployerConfig{ ApiUrl: fApiUrl, + ApiVersion: fApiVersion, ApiKey: fApiKey, AllowInsecureConnections: true, AutoRestart: true, diff --git a/internal/pkg/core/deployer/providers/1panel-site/1panel_site.go b/internal/pkg/core/deployer/providers/1panel-site/1panel_site.go index 7d360c77..afecaf74 100644 --- a/internal/pkg/core/deployer/providers/1panel-site/1panel_site.go +++ b/internal/pkg/core/deployer/providers/1panel-site/1panel_site.go @@ -12,12 +12,14 @@ import ( "github.com/usual2970/certimate/internal/pkg/core/deployer" "github.com/usual2970/certimate/internal/pkg/core/uploader" uploadersp "github.com/usual2970/certimate/internal/pkg/core/uploader/providers/1panel-ssl" - opsdk "github.com/usual2970/certimate/internal/pkg/sdk3rd/1panel" + onepanelsdk "github.com/usual2970/certimate/internal/pkg/sdk3rd/1panel" ) type DeployerConfig struct { // 1Panel 地址。 ApiUrl string `json:"apiUrl"` + // 1Panel 版本。 + ApiVersion string `json:"apiVersion"` // 1Panel 接口密钥。 ApiKey string `json:"apiKey"` // 是否允许不安全的连接。 @@ -35,7 +37,7 @@ type DeployerConfig struct { type DeployerProvider struct { config *DeployerConfig logger *slog.Logger - sdkClient *opsdk.Client + sdkClient *onepanelsdk.Client sslUploader uploader.Uploader } @@ -46,14 +48,15 @@ func NewDeployer(config *DeployerConfig) (*DeployerProvider, error) { panic("config is nil") } - client, err := createSdkClient(config.ApiUrl, config.ApiKey, config.AllowInsecureConnections) + client, err := createSdkClient(config.ApiUrl, config.ApiVersion, config.ApiKey, config.AllowInsecureConnections) if err != nil { return nil, fmt.Errorf("failed to create sdk client: %w", err) } uploader, err := uploadersp.NewUploader(&uploadersp.UploaderConfig{ - ApiUrl: config.ApiUrl, - ApiKey: config.ApiKey, + ApiUrl: config.ApiUrl, + ApiVersion: config.ApiVersion, + ApiKey: config.ApiKey, }) if err != nil { return nil, fmt.Errorf("failed to create ssl uploader: %w", err) @@ -103,7 +106,7 @@ func (d *DeployerProvider) deployToWebsite(ctx context.Context, certPEM string, } // 获取网站 HTTPS 配置 - getHttpsConfReq := &opsdk.GetHttpsConfRequest{ + getHttpsConfReq := &onepanelsdk.GetHttpsConfRequest{ WebsiteID: d.config.WebsiteId, } getHttpsConfResp, err := d.sdkClient.GetHttpsConf(getHttpsConfReq) @@ -122,7 +125,7 @@ func (d *DeployerProvider) deployToWebsite(ctx context.Context, certPEM string, // 修改网站 HTTPS 配置 certId, _ := strconv.ParseInt(upres.CertId, 10, 64) - updateHttpsConfReq := &opsdk.UpdateHttpsConfRequest{ + updateHttpsConfReq := &onepanelsdk.UpdateHttpsConfRequest{ WebsiteID: d.config.WebsiteId, Type: "existed", WebsiteSSLID: certId, @@ -147,7 +150,7 @@ func (d *DeployerProvider) deployToCertificate(ctx context.Context, certPEM stri } // 获取证书详情 - getWebsiteSSLReq := &opsdk.GetWebsiteSSLRequest{ + getWebsiteSSLReq := &onepanelsdk.GetWebsiteSSLRequest{ SSLID: d.config.CertificateId, } getWebsiteSSLResp, err := d.sdkClient.GetWebsiteSSL(getWebsiteSSLReq) @@ -157,7 +160,7 @@ func (d *DeployerProvider) deployToCertificate(ctx context.Context, certPEM stri } // 更新证书 - uploadWebsiteSSLReq := &opsdk.UploadWebsiteSSLRequest{ + uploadWebsiteSSLReq := &onepanelsdk.UploadWebsiteSSLRequest{ Type: "paste", SSLID: d.config.CertificateId, Description: getWebsiteSSLResp.Data.Description, @@ -173,16 +176,20 @@ func (d *DeployerProvider) deployToCertificate(ctx context.Context, certPEM stri return nil } -func createSdkClient(apiUrl, apiKey string, skipTlsVerify bool) (*opsdk.Client, error) { +func createSdkClient(apiUrl, apiVersion, apiKey string, skipTlsVerify bool) (*onepanelsdk.Client, error) { if _, err := url.Parse(apiUrl); err != nil { return nil, errors.New("invalid 1panel api url") } + if apiVersion == "" { + return nil, errors.New("invalid 1panel api version") + } + if apiKey == "" { return nil, errors.New("invalid 1panel api key") } - client := opsdk.NewClient(apiUrl, apiKey) + client := onepanelsdk.NewClient(apiUrl, apiVersion, apiKey) if skipTlsVerify { client.WithTLSConfig(&tls.Config{InsecureSkipVerify: true}) } diff --git a/internal/pkg/core/deployer/providers/1panel-site/1panel_site_test.go b/internal/pkg/core/deployer/providers/1panel-site/1panel_site_test.go index 702584e3..1d5bafef 100644 --- a/internal/pkg/core/deployer/providers/1panel-site/1panel_site_test.go +++ b/internal/pkg/core/deployer/providers/1panel-site/1panel_site_test.go @@ -15,6 +15,7 @@ var ( fInputCertPath string fInputKeyPath string fApiUrl string + fApiVersion string fApiKey string fWebsiteId int64 ) @@ -25,6 +26,7 @@ func init() { flag.StringVar(&fInputCertPath, argsPrefix+"INPUTCERTPATH", "", "") flag.StringVar(&fInputKeyPath, argsPrefix+"INPUTKEYPATH", "", "") flag.StringVar(&fApiUrl, argsPrefix+"APIURL", "", "") + flag.StringVar(&fApiVersion, argsPrefix+"APIVERSION", "v1", "") flag.StringVar(&fApiKey, argsPrefix+"APIKEY", "", "") flag.Int64Var(&fWebsiteId, argsPrefix+"WEBSITEID", 0, "") } @@ -36,6 +38,7 @@ Shell command to run this test: --CERTIMATE_DEPLOYER_1PANELSITE_INPUTCERTPATH="/path/to/your-input-cert.pem" \ --CERTIMATE_DEPLOYER_1PANELSITE_INPUTKEYPATH="/path/to/your-input-key.pem" \ --CERTIMATE_DEPLOYER_1PANELSITE_APIURL="http://127.0.0.1:20410" \ + --CERTIMATE_DEPLOYER_1PANELSITE_APIVERSION="v1" \ --CERTIMATE_DEPLOYER_1PANELSITE_APIKEY="your-api-key" \ --CERTIMATE_DEPLOYER_1PANELSITE_WEBSITEID="your-website-id" */ @@ -48,12 +51,14 @@ func TestDeploy(t *testing.T) { fmt.Sprintf("INPUTCERTPATH: %v", fInputCertPath), fmt.Sprintf("INPUTKEYPATH: %v", fInputKeyPath), fmt.Sprintf("APIURL: %v", fApiUrl), + fmt.Sprintf("APIVERSION: %v", fApiVersion), fmt.Sprintf("APIKEY: %v", fApiKey), fmt.Sprintf("WEBSITEID: %v", fWebsiteId), }, "\n")) deployer, err := provider.NewDeployer(&provider.DeployerConfig{ ApiUrl: fApiUrl, + ApiVersion: fApiVersion, ApiKey: fApiKey, AllowInsecureConnections: true, ResourceType: provider.RESOURCE_TYPE_WEBSITE, diff --git a/internal/pkg/core/uploader/providers/1panel-ssl/1panel_ssl.go b/internal/pkg/core/uploader/providers/1panel-ssl/1panel_ssl.go index e5a0b0ba..63900125 100644 --- a/internal/pkg/core/uploader/providers/1panel-ssl/1panel_ssl.go +++ b/internal/pkg/core/uploader/providers/1panel-ssl/1panel_ssl.go @@ -10,12 +10,14 @@ import ( "time" "github.com/usual2970/certimate/internal/pkg/core/uploader" - opsdk "github.com/usual2970/certimate/internal/pkg/sdk3rd/1panel" + onepanelsdk "github.com/usual2970/certimate/internal/pkg/sdk3rd/1panel" ) type UploaderConfig struct { // 1Panel 地址。 ApiUrl string `json:"apiUrl"` + // 1Panel 版本。 + ApiVersion string `json:"apiVersion"` // 1Panel 接口密钥。 ApiKey string `json:"apiKey"` } @@ -23,7 +25,7 @@ type UploaderConfig struct { type UploaderProvider struct { config *UploaderConfig logger *slog.Logger - sdkClient *opsdk.Client + sdkClient *onepanelsdk.Client } var _ uploader.Uploader = (*UploaderProvider)(nil) @@ -33,7 +35,7 @@ func NewUploader(config *UploaderConfig) (*UploaderProvider, error) { panic("config is nil") } - client, err := createSdkClient(config.ApiUrl, config.ApiKey) + client, err := createSdkClient(config.ApiUrl, config.ApiVersion, config.ApiKey) if err != nil { return nil, fmt.Errorf("failed to create sdk client: %w", err) } @@ -67,7 +69,7 @@ func (u *UploaderProvider) Upload(ctx context.Context, certPEM string, privkeyPE certName := fmt.Sprintf("certimate-%d", time.Now().UnixMilli()) // 上传证书 - uploadWebsiteSSLReq := &opsdk.UploadWebsiteSSLRequest{ + uploadWebsiteSSLReq := &onepanelsdk.UploadWebsiteSSLRequest{ Type: "paste", Description: certName, Certificate: certPEM, @@ -99,7 +101,7 @@ func (u *UploaderProvider) getCertIfExists(ctx context.Context, certPEM string, default: } - searchWebsiteSSLReq := &opsdk.SearchWebsiteSSLRequest{ + searchWebsiteSSLReq := &onepanelsdk.SearchWebsiteSSLRequest{ Page: searchWebsiteSSLPageNumber, PageSize: searchWebsiteSSLPageSize, } @@ -130,15 +132,19 @@ func (u *UploaderProvider) getCertIfExists(ctx context.Context, certPEM string, return nil, nil } -func createSdkClient(apiUrl, apiKey string) (*opsdk.Client, error) { +func createSdkClient(apiUrl, apiVersion, apiKey string) (*onepanelsdk.Client, error) { if _, err := url.Parse(apiUrl); err != nil { return nil, errors.New("invalid 1panel api url") } + if apiVersion == "" { + return nil, errors.New("invalid 1panel api version") + } + if apiKey == "" { return nil, errors.New("invalid 1panel api key") } - client := opsdk.NewClient(apiUrl, apiKey) + client := onepanelsdk.NewClient(apiUrl, apiVersion, apiKey) return client, nil } diff --git a/internal/pkg/core/uploader/providers/1panel-ssl/1panel_ssl_test.go b/internal/pkg/core/uploader/providers/1panel-ssl/1panel_ssl_test.go index 257030f5..cfb250be 100644 --- a/internal/pkg/core/uploader/providers/1panel-ssl/1panel_ssl_test.go +++ b/internal/pkg/core/uploader/providers/1panel-ssl/1panel_ssl_test.go @@ -16,6 +16,7 @@ var ( fInputCertPath string fInputKeyPath string fApiUrl string + fApiVersion string fApiKey string ) @@ -25,6 +26,7 @@ func init() { flag.StringVar(&fInputCertPath, argsPrefix+"INPUTCERTPATH", "", "") flag.StringVar(&fInputKeyPath, argsPrefix+"INPUTKEYPATH", "", "") flag.StringVar(&fApiUrl, argsPrefix+"APIURL", "", "") + flag.StringVar(&fApiVersion, argsPrefix+"APIVERSION", "v1", "") flag.StringVar(&fApiKey, argsPrefix+"APIKEY", "", "") } @@ -35,6 +37,7 @@ Shell command to run this test: --CERTIMATE_UPLOADER_1PANELSSL_INPUTCERTPATH="/path/to/your-input-cert.pem" \ --CERTIMATE_UPLOADER_1PANELSSL_INPUTKEYPATH="/path/to/your-input-key.pem" \ --CERTIMATE_UPLOADER_1PANELSSL_APIURL="http://127.0.0.1:20410" \ + --CERTIMATE_UPLOADER_1PANELSSL_APIVERSION="v1" \ --CERTIMATE_UPLOADER_1PANELSSL_APIKEY="your-api-key" */ func TestDeploy(t *testing.T) { @@ -46,12 +49,14 @@ func TestDeploy(t *testing.T) { fmt.Sprintf("INPUTCERTPATH: %v", fInputCertPath), fmt.Sprintf("INPUTKEYPATH: %v", fInputKeyPath), fmt.Sprintf("APIURL: %v", fApiUrl), + fmt.Sprintf("APIVERSION: %v", fApiVersion), fmt.Sprintf("APIKEY: %v", fApiKey), }, "\n")) uploader, err := provider.NewUploader(&provider.UploaderConfig{ - ApiUrl: fApiUrl, - ApiKey: fApiKey, + ApiUrl: fApiUrl, + ApiVersion: fApiVersion, + ApiKey: fApiKey, }) if err != nil { t.Errorf("err: %+v", err) diff --git a/internal/pkg/sdk3rd/1panel/client.go b/internal/pkg/sdk3rd/1panel/client.go index e8946bae..4480ae49 100644 --- a/internal/pkg/sdk3rd/1panel/client.go +++ b/internal/pkg/sdk3rd/1panel/client.go @@ -14,19 +14,25 @@ import ( ) type Client struct { - apiHost string - apiKey string + apiHost string + apiVersion string + apiKey string client *resty.Client } -func NewClient(apiHost, apiKey string) *Client { +func NewClient(apiHost, apiVersion, apiKey string) *Client { client := resty.New() + if apiVersion == "" { + apiVersion = "v1" + } + return &Client{ - apiHost: strings.TrimRight(apiHost, "/"), - apiKey: apiKey, - client: client, + apiHost: strings.TrimRight(apiHost, "/"), + apiVersion: apiVersion, + apiKey: apiKey, + client: client, } } @@ -49,7 +55,7 @@ func (c *Client) generateToken(timestamp string) string { func (c *Client) sendRequest(method string, path string, params interface{}) (*resty.Response, error) { req := c.client.R() req.Method = method - req.URL = c.apiHost + "/api/v1" + path + req.URL = c.apiHost + "/api/" + c.apiVersion + path if strings.EqualFold(method, http.MethodGet) { qs := make(map[string]string) if params != nil { diff --git a/migrations/1747389600_upgrade.go b/migrations/1747389600_upgrade.go new file mode 100644 index 00000000..aa5e2e3a --- /dev/null +++ b/migrations/1747389600_upgrade.go @@ -0,0 +1,44 @@ +package migrations + +import ( + "github.com/pocketbase/pocketbase/core" + m "github.com/pocketbase/pocketbase/migrations" +) + +func init() { + m.Register(func(app core.App) error { + // migrate data + { + accesses, err := app.FindAllRecords("access") + if err != nil { + return err + } + + for _, access := range accesses { + changed := false + + if access.GetString("provider") == "1panel" { + config := make(map[string]any) + if err := access.UnmarshalJSONField("config", &config); err != nil { + return err + } + + config["apiVersion"] = "v1" + access.Set("config", config) + changed = true + } + + if changed { + err = app.Save(access) + if err != nil { + return err + } + } + } + } + + return nil + }, func(app core.App) error { + return nil + }) +} diff --git a/ui/src/components/access/AccessForm1PanelConfig.tsx b/ui/src/components/access/AccessForm1PanelConfig.tsx index c0762bbd..29481f15 100644 --- a/ui/src/components/access/AccessForm1PanelConfig.tsx +++ b/ui/src/components/access/AccessForm1PanelConfig.tsx @@ -1,5 +1,5 @@ import { useTranslation } from "react-i18next"; -import { Form, type FormInstance, Input, Switch } from "antd"; +import { Form, type FormInstance, Input, Select, Switch } from "antd"; import { createSchemaFieldRule } from "antd-zod"; import { z } from "zod"; @@ -18,6 +18,7 @@ export type AccessForm1PanelConfigProps = { const initFormModel = (): AccessForm1PanelConfigFieldValues => { return { apiUrl: "http://:20410/", + apiVersion: "v1", apiKey: "", }; }; @@ -27,6 +28,7 @@ const AccessForm1PanelConfig = ({ form: formInst, formName, disabled, initialVal const formSchema = z.object({ apiUrl: z.string().url(t("common.errmsg.url_invalid")), + apiVersion: z.string().nonempty(t("access.form.1panel_api_version.placeholder")), apiKey: z .string() .min(1, t("access.form.1panel_api_key.placeholder")) @@ -53,6 +55,10 @@ const AccessForm1PanelConfig = ({ form: formInst, formName, disabled, initialVal + +