Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions agent/app/service/website_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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")
}
Expand All @@ -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
}
Comment thread
zhengkunwang223 marked this conversation as resolved.

func (w WebsiteTemplateService) DeleteTemplate(id uint) error {
template, err := websiteTemplateRepo.GetFirst(repo.WithByID(id))
if err != nil {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -416,4 +438,3 @@ func copyFile(src, dst string) error {
_, err = io.Copy(dstFile, srcFile)
return err
}

1 change: 1 addition & 0 deletions core/constant/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ var WebUrlMap = map[string]struct{}{
"/toolbox/clean": {},

"/websites": {},
"/websites/templates": {},
"/websites/ssl": {},
"/websites/runtimes/php": {},
"/websites/runtimes/node": {},
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/ai/agents/model/add/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion frontend/src/views/website/template/operate/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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')));
Comment thread
zhengkunwang223 marked this conversation as resolved.
return;
}
callback();
},
trigger: 'change',
},
],
};

const variables = ref<Website.TemplateVariable[]>([]);
Expand Down Expand Up @@ -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 {}
Expand Down
Loading