From 2624238354902898fe6dd52d2e6160e7a7722593 Mon Sep 17 00:00:00 2001
From: zhengkunwang <31820853+zhengkunwang223@users.noreply.github.com>
Date: Thu, 28 Sep 2023 15:30:17 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BD=91=E7=AB=99=E4=B8=BB=E5=9F=9F?=
=?UTF-8?q?=E5=90=8D=E6=94=AF=E6=8C=81=E5=9F=9F=E5=90=8D=EF=BC=9A=E7=AB=AF?=
=?UTF-8?q?=E5=8F=A3=20(#2410)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Refs https://github.com/1Panel-dev/1Panel/issues/2333
---
backend/app/service/website.go | 19 ++++++++----------
frontend/src/global/form-rules.ts | 20 +++++++++++++++++++
frontend/src/lang/modules/en.ts | 1 +
frontend/src/lang/modules/tw.ts | 1 +
frontend/src/lang/modules/zh.ts | 1 +
.../views/website/website/create/index.vue | 10 ++++++----
6 files changed, 37 insertions(+), 15 deletions(-)
diff --git a/backend/app/service/website.go b/backend/app/service/website.go
index e3205a28d..992c59395 100644
--- a/backend/app/service/website.go
+++ b/backend/app/service/website.go
@@ -185,10 +185,12 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error)
return err
}
defaultHttpPort := nginxInstall.HttpPort
+ primaryDomainArray := strings.Split(create.PrimaryDomain, ":")
+ primaryDomain := primaryDomainArray[0]
defaultDate, _ := time.Parse(constant.DateLayout, constant.DefaultDate)
website := &model.Website{
- PrimaryDomain: create.PrimaryDomain,
+ PrimaryDomain: primaryDomain,
Type: create.Type,
Alias: create.Alias,
Remark: create.Remark,
@@ -263,9 +265,8 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error)
website.RuntimeID = runtime.ID
if runtime.Resource == constant.ResourceAppstore {
var (
- req request.AppInstallCreate
- nginxInstall model.AppInstall
- install *model.AppInstall
+ req request.AppInstallCreate
+ install *model.AppInstall
)
reg, _ := regexp.Compile(`[^a-z0-9_-]+`)
req.Name = reg.ReplaceAllString(strings.ToLower(create.PrimaryDomain), "")
@@ -273,10 +274,6 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error)
req.Params = create.AppInstall.Params
req.Params["IMAGE_NAME"] = runtime.Image
req.AppContainerConfig = create.AppInstall.AppContainerConfig
- nginxInstall, err = getAppInstallByKey(constant.AppOpenresty)
- if err != nil {
- return err
- }
req.Params["PANEL_WEBSITE_DIR"] = path.Join(nginxInstall.GetPath(), "/www")
tx, installCtx := getTxAndContext()
install, err = NewIAppService().Install(installCtx, req)
@@ -301,9 +298,9 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error)
}
var domains []model.WebsiteDomain
- domains = append(domains, model.WebsiteDomain{Domain: website.PrimaryDomain, Port: defaultHttpPort})
- otherDomainArray := strings.Split(create.OtherDomains, "\n")
- for _, domain := range otherDomainArray {
+ domainArray := strings.Split(create.OtherDomains, "\n")
+ domainArray = append(domainArray, create.PrimaryDomain)
+ for _, domain := range domainArray {
if domain == "" {
continue
}
diff --git a/frontend/src/global/form-rules.ts b/frontend/src/global/form-rules.ts
index 0e7e2d665..b90ac8c76 100644
--- a/frontend/src/global/form-rules.ts
+++ b/frontend/src/global/form-rules.ts
@@ -225,6 +225,20 @@ const checkDomain = (rule: any, value: any, callback: any) => {
}
};
+const checkDomainWithPort = (rule: any, value: any, callback: any) => {
+ if (value === '' || typeof value === 'undefined' || value == null) {
+ callback(new Error(i18n.global.t('commons.rule.domain')));
+ } else {
+ const reg =
+ /^([\w\u4e00-\u9fa5\-\*]{1,100}\.){1,10}([\w\u4e00-\u9fa5\-]{1,24}|[\w\u4e00-\u9fa5\-]{1,24}\.[\w\u4e00-\u9fa5\-]{1,24})(:\d{1,5})?$/;
+ if (!reg.test(value) && value !== '') {
+ callback(new Error(i18n.global.t('commons.rule.domain')));
+ } else {
+ callback();
+ }
+ }
+};
+
const checkIntegerNumber = (rule: any, value: any, callback: any) => {
if (value === '' || typeof value === 'undefined' || value == null) {
callback(new Error(i18n.global.t('commons.rule.integer')));
@@ -442,6 +456,7 @@ interface CommonRule {
containerName: FormItemRule;
disabledFunctions: FormItemRule;
leechExts: FormItemRule;
+ domainWithPort: FormItemRule;
paramCommon: FormItemRule;
paramComplexity: FormItemRule;
@@ -626,4 +641,9 @@ export const Rules: CommonRule = {
trigger: 'blur',
validator: checkParamSimple,
},
+ domainWithPort: {
+ required: true,
+ validator: checkDomainWithPort,
+ trigger: 'blur',
+ },
};
diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts
index e030d353f..d6c647b81 100644
--- a/frontend/src/lang/modules/en.ts
+++ b/frontend/src/lang/modules/en.ts
@@ -1542,6 +1542,7 @@ const message = {
runDirHelper2: 'Please ensure that the secondary running directory is under the index directory',
openrestryHelper:
'OpenResty default HTTP port: {0} HTTPS port: {1}, which may affect website domain name access and HTTPS forced redirect',
+ primaryDomainHelper: 'Support domain name: port',
},
php: {
short_open_tag: 'Short tag support',
diff --git a/frontend/src/lang/modules/tw.ts b/frontend/src/lang/modules/tw.ts
index 4c9500565..e946761ae 100644
--- a/frontend/src/lang/modules/tw.ts
+++ b/frontend/src/lang/modules/tw.ts
@@ -1465,6 +1465,7 @@ const message = {
retainConfig: '是否保留 php-fpm.conf 和 php.ini 文件',
runDirHelper2: '請確保二級運行目錄位於 index 目錄下',
openrestryHelper: 'OpenResty 默認 HTTP 端口:{0} HTTPS 端口:{1},可能影響網站域名訪問和 HTTPS 強制跳轉',
+ primaryDomainHelper: '支援網域:port',
},
php: {
short_open_tag: '短標簽支持',
diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts
index a9b40f5cf..7d7a7c8fb 100644
--- a/frontend/src/lang/modules/zh.ts
+++ b/frontend/src/lang/modules/zh.ts
@@ -1465,6 +1465,7 @@ const message = {
retainConfig: '是否保留 php-fpm.conf 和 php.ini 文件',
runDirHelper2: '请确保二级运行目录位于 index 目录下',
openrestryHelper: 'OpenResty 默认 HTTP 端口:{0} HTTPS 端口 :{1},可能影响网站域名访问和 HTTPS 强制跳转',
+ primaryDomainHelper: '支持域名:端口',
},
php: {
short_open_tag: '短标签支持',
diff --git a/frontend/src/views/website/website/create/index.vue b/frontend/src/views/website/website/create/index.vue
index 25cb9000d..721972834 100644
--- a/frontend/src/views/website/website/create/index.vue
+++ b/frontend/src/views/website/website/create/index.vue
@@ -246,6 +246,7 @@
@@ -364,7 +365,7 @@ const website = ref({
proxyAddress: '',
});
const rules = ref({
- primaryDomain: [Rules.domain],
+ primaryDomain: [Rules.domainWithPort],
alias: [Rules.linuxName],
type: [Rules.requiredInput],
webSiteGroupId: [Rules.requiredSelectBusiness],
@@ -504,7 +505,7 @@ const changeRuntime = (runID: number) => {
if (item.id === runID) {
runtimeResource.value = item.resource;
if (item.resource === 'appstore') {
- getAppDetailByID(item.appDetailId);
+ getAppDetailByID(item.appDetailID);
}
}
});
@@ -519,7 +520,7 @@ const getRuntimes = async () => {
website.value.runtimeID = first.id;
runtimeResource.value = first.resource;
if (first.resource === 'appstore') {
- getAppDetailByID(first.appDetailId);
+ getAppDetailByID(first.appDetailID);
}
}
} catch (error) {}
@@ -583,7 +584,8 @@ const submit = async (formEl: FormInstance | undefined) => {
};
const changeAlias = (value: string) => {
- website.value.alias = value;
+ const domain = value.split(':')[0];
+ website.value.alias = domain;
};
function compareVersions(version1: string, version2: string): boolean {