diff --git a/api/config/add.go b/api/config/add.go index 93875353..834b6ebd 100644 --- a/api/config/add.go +++ b/api/config/add.go @@ -18,7 +18,7 @@ import ( func AddConfig(c *gin.Context) { var json struct { Name string `json:"name" binding:"required"` - NewFilepath string `json:"new_filepath" binding:"required"` + BaseDir string `json:"base_dir"` Content string `json:"content"` Overwrite bool `json:"overwrite"` SyncNodeIds []uint64 `json:"sync_node_ids"` @@ -30,10 +30,11 @@ func AddConfig(c *gin.Context) { name := json.Name content := json.Content - path := json.NewFilepath + dir := nginx.GetConfPath(json.BaseDir) + path := filepath.Join(dir, json.Name) if !helper.IsUnderDirectory(path, nginx.GetConfPath()) { c.JSON(http.StatusForbidden, gin.H{ - "message": "new filepath is not under the nginx conf path", + "message": "filepath is not under the nginx conf path", }) return } @@ -46,7 +47,6 @@ func AddConfig(c *gin.Context) { } // check if the dir exists, if not, use mkdirAll to create the dir - dir := filepath.Dir(path) if !helper.FileExists(dir) { err := os.MkdirAll(dir, 0755) if err != nil { @@ -89,7 +89,7 @@ func AddConfig(c *gin.Context) { return } - err = config.SyncToRemoteServer(cfg, json.NewFilepath) + err = config.SyncToRemoteServer(cfg, path) if err != nil { api.ErrHandler(c, err) return diff --git a/api/config/modify.go b/api/config/modify.go index c232a6d6..2d24dd7b 100644 --- a/api/config/modify.go +++ b/api/config/modify.go @@ -22,7 +22,6 @@ type EditConfigJson struct { func EditConfig(c *gin.Context) { relativePath := c.Param("path") var json struct { - Name string `json:"name" binding:"required"` Content string `json:"content"` SyncOverwrite bool `json:"sync_overwrite"` SyncNodeIds []uint64 `json:"sync_node_ids"` diff --git a/api/config/rename.go b/api/config/rename.go index 4e5efb94..c308aedc 100644 --- a/api/config/rename.go +++ b/api/config/rename.go @@ -8,9 +8,9 @@ import ( "github.com/0xJacky/Nginx-UI/model" "github.com/0xJacky/Nginx-UI/query" "github.com/gin-gonic/gin" - "github.com/uozi-tech/cosy/logger" "net/http" "os" + "path/filepath" "strings" ) @@ -21,10 +21,11 @@ func Rename(c *gin.Context) { NewName string `json:"new_name"` SyncNodeIds []uint64 `json:"sync_node_ids" gorm:"serializer:json"` } + if !api.BindAndValid(c, &json) { return } - logger.Debug(json) + if json.OrigName == json.NewName { c.JSON(http.StatusOK, gin.H{ "message": "ok", @@ -97,6 +98,6 @@ func Rename(c *gin.Context) { } c.JSON(http.StatusOK, gin.H{ - "path": strings.TrimLeft(newFullPath, nginx.GetConfPath()), + "path": strings.TrimLeft(filepath.Join(json.BasePath, json.NewName), "/"), }) } diff --git a/app/src/components/StdDesign/StdDataDisplay/StdTable.vue b/app/src/components/StdDesign/StdDataDisplay/StdTable.vue index 98b40588..6b5e8a06 100644 --- a/app/src/components/StdDesign/StdDataDisplay/StdTable.vue +++ b/app/src/components/StdDesign/StdDataDisplay/StdTable.vue @@ -452,14 +452,6 @@ const paginationSize = computed(() => { > {{ $gettext('Batch Modify') }} - diff --git a/app/src/views/config/ConfigEditor.vue b/app/src/views/config/ConfigEditor.vue index bdb62e95..038e2d0e 100644 --- a/app/src/views/config/ConfigEditor.vue +++ b/app/src/views/config/ConfigEditor.vue @@ -20,8 +20,10 @@ import _ from 'lodash' const settings = useSettingsStore() const route = useRoute() const router = useRouter() + +// eslint-disable-next-line vue/require-typed-ref const refForm = ref() -const refInspectConfig = ref() +const refInspectConfig = useTemplateRef('refInspectConfig') const origName = ref('') const addMode = computed(() => !route.params.name) const errors = ref({}) @@ -155,11 +157,10 @@ onMounted(async () => { }) function save() { - refForm.value.validate().then(() => { - config.save(addMode.value ? null : relativePath.value, { - name: data.value.name, - filepath: data.value.filepath, - new_filepath: newPath.value, + refForm.value?.validate().then(() => { + config.save(addMode.value ? undefined : relativePath.value, { + name: addMode.value ? data.value.name : undefined, + base_dir: addMode.value ? basePath.value : undefined, content: data.value.content, sync_node_ids: data.value.sync_node_ids, sync_overwrite: data.value.sync_overwrite, @@ -171,7 +172,7 @@ function save() { errors.value = e.errors message.error($gettext('Save error %{msg}', { msg: e.message ?? '' })) }).finally(() => { - refInspectConfig.value.test() + refInspectConfig.value?.test() }) }) } @@ -256,7 +257,8 @@ function goBack() { name="name" :label="$gettext('Name')" > - + +