mirror of
https://gitee.com/fit2cloud-feizhiyun/1Panel.git
synced 2026-11-20 07:49:30 +08:00
fix: Fixed bug with website template (#13484)
This commit is contained in:
@@ -75,6 +75,9 @@ func (w WebsiteTemplateService) PageTemplate(req request.WebsiteTemplateSearch)
|
||||
}
|
||||
|
||||
func (w WebsiteTemplateService) CreateTemplate(req request.WebsiteTemplateCreate) error {
|
||||
if err := validateWebsiteTemplateFile(req.Type, req.FilePath); err != nil {
|
||||
return err
|
||||
}
|
||||
if exist, _ := websiteTemplateRepo.GetFirst(repo.WithByName(req.Name)); exist != nil {
|
||||
return buserr.New("ErrNameIsExist")
|
||||
}
|
||||
@@ -94,6 +97,9 @@ func (w WebsiteTemplateService) UpdateTemplate(req request.WebsiteTemplateUpdate
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateWebsiteTemplateFile(req.Type, req.FilePath); err != nil {
|
||||
return err
|
||||
}
|
||||
if exist, _ := websiteTemplateRepo.GetFirst(repo.WithByName(req.Name), repo.WithByNOTID(req.ID)); exist != nil {
|
||||
return buserr.New("ErrNameIsExist")
|
||||
}
|
||||
@@ -109,6 +115,22 @@ func (w WebsiteTemplateService) UpdateTemplate(req request.WebsiteTemplateUpdate
|
||||
return websiteTemplateRepo.Save(template)
|
||||
}
|
||||
|
||||
func validateWebsiteTemplateFile(templateType, filePath string) error {
|
||||
if templateType != "multi" {
|
||||
return nil
|
||||
}
|
||||
if filePath == "" {
|
||||
return buserr.WithName("ErrFileNotFound", "ZIP")
|
||||
}
|
||||
if _, err := os.Stat(filePath); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return buserr.WithName("ErrFileNotFound", "ZIP")
|
||||
}
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w WebsiteTemplateService) DeleteTemplate(id uint) error {
|
||||
template, err := websiteTemplateRepo.GetFirst(repo.WithByID(id))
|
||||
if err != nil {
|
||||
@@ -297,7 +319,7 @@ func renderToDir(template *model.WebsiteTemplate, values map[string]string, outp
|
||||
|
||||
func unzipAndRender(zipPath, outputDir string, values map[string]string) error {
|
||||
if zipPath == "" {
|
||||
return buserr.New("ErrFileNotFound")
|
||||
return buserr.WithName("ErrFileNotFound", "ZIP")
|
||||
}
|
||||
reader, err := zip.OpenReader(zipPath)
|
||||
if err != nil {
|
||||
@@ -348,7 +370,7 @@ func isTextFile(name string) bool {
|
||||
|
||||
func renderMainHTMLFromZip(zipPath string, values map[string]string) (string, error) {
|
||||
if zipPath == "" {
|
||||
return "", buserr.New("ErrFileNotFound")
|
||||
return "", buserr.WithName("ErrFileNotFound", "ZIP")
|
||||
}
|
||||
reader, err := zip.OpenReader(zipPath)
|
||||
if err != nil {
|
||||
@@ -368,7 +390,7 @@ func renderMainHTMLFromZip(zipPath string, values map[string]string) (string, er
|
||||
}
|
||||
}
|
||||
if mainFile == nil {
|
||||
return "", buserr.New("ErrFileNotFound")
|
||||
return "", buserr.WithName("ErrFileNotFound", "index.html")
|
||||
}
|
||||
rc, err := mainFile.Open()
|
||||
if err != nil {
|
||||
@@ -416,4 +438,3 @@ func copyFile(src, dst string) error {
|
||||
_, err = io.Copy(dstFile, srcFile)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -151,6 +151,7 @@ var WebUrlMap = map[string]struct{}{
|
||||
"/toolbox/clean": {},
|
||||
|
||||
"/websites": {},
|
||||
"/websites/templates": {},
|
||||
"/websites/ssl": {},
|
||||
"/websites/runtimes/php": {},
|
||||
"/websites/runtimes/node": {},
|
||||
|
||||
@@ -72,7 +72,7 @@
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-switch v-model="form.validateAvailability" />
|
||||
<span class="ml-2">{{ $t('aiTools.agents.validateAvailability') }}</span>
|
||||
<el-text class="ml-2">{{ $t('aiTools.agents.validateAvailability') }}</el-text>
|
||||
<span class="input-help">
|
||||
{{
|
||||
isImageAPIType
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
/>
|
||||
<span class="input-help">{{ $t('template.autoDetectHelper') }}</span>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="form.type === 'multi'" :label="$t('template.upload')">
|
||||
<el-form-item v-if="form.type === 'multi'" :label="$t('template.upload')" prop="filePath">
|
||||
<el-upload :show-file-list="false" :before-upload="handleUpload" accept=".zip" action="#">
|
||||
<el-button type="primary" plain>{{ $t('template.upload') }}</el-button>
|
||||
</el-upload>
|
||||
@@ -140,6 +140,18 @@ const form = reactive(initForm());
|
||||
const rules = {
|
||||
name: [{ required: true, message: i18n.global.t('commons.rule.requiredInput'), trigger: 'blur' }],
|
||||
type: [{ required: true, message: i18n.global.t('commons.rule.requiredSelect'), trigger: 'change' }],
|
||||
filePath: [
|
||||
{
|
||||
validator: (_rule, value, callback) => {
|
||||
if (form.type === 'multi' && !value) {
|
||||
callback(new Error(i18n.global.t('commons.rule.requiredSelect')));
|
||||
return;
|
||||
}
|
||||
callback();
|
||||
},
|
||||
trigger: 'change',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const variables = ref<Website.TemplateVariable[]>([]);
|
||||
@@ -178,6 +190,7 @@ const handleUpload = async (file: globalThis.File) => {
|
||||
try {
|
||||
const res = await uploadTemplateZip(file);
|
||||
form.filePath = res.data.filePath;
|
||||
formRef.value?.clearValidate('filePath');
|
||||
mergeDetectedKeys(res.data.variables || []);
|
||||
MsgSuccess(i18n.global.t('commons.msg.uploadSuccess'));
|
||||
} catch {}
|
||||
|
||||
Reference in New Issue
Block a user