fix: fail to create config #724 #720

This commit is contained in:
Jacky 2024-11-15 19:30:03 +08:00
parent 56e82d9c5a
commit a2c0e804a4
No known key found for this signature in database
GPG key ID: 215C21B10DF38B4D
5 changed files with 19 additions and 25 deletions

View file

@ -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

View file

@ -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"`

View file

@ -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), "/"),
})
}

View file

@ -452,14 +452,6 @@ const paginationSize = computed(() => {
>
{{ $gettext('Batch Modify') }}
</AButton>
<Export
v-if="props.exportExcel"
:columns="props.columns"
:api="props.api"
:total="pagination.total"
:query="params"
:ids="selectedRowKeys"
/>
<slot name="append-search" />
</ASpace>
</template>

View file

@ -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')"
>
<ConfigName :name="data.name" :dir="data.dir" />
<AInput v-if="addMode" v-model:value="data.name" />
<ConfigName v-else :name="data.name" :dir="data.dir" />
</AFormItem>
<AFormItem
v-if="!addMode"