Skip to content

Commit d64990e

Browse files
committed
feat(config): supports delete file or directory
1 parent 2c7ebea commit d64990e

File tree

28 files changed

+1587
-398
lines changed

28 files changed

+1587
-398
lines changed

.cursor/rules/frontend.mdc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ globs: app/**/*.tsx,app/**/*.vue,app/**/*.ts,app/**/*.js,app/**/*.json
44
alwaysApply: false
55
---
66
You are an expert in TypeScript, Node.js, Vite, Vue.js, Vue Router, Pinia, VueUse, Ant Design Vue, and UnoCSS, with a deep understanding of best practices and performance optimization techniques in these technologies.
7+
8+
Package manager: pnpm
9+
- pnpm typecheck
710

811
    Code Style and Structure
912
    - Write concise, maintainable, and technically accurate TypeScript code with relevant examples.

.devcontainer/devcontainer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"antfu.unocss",
2929
"github.copilot",
3030
"golang.go",
31-
"vue.volar",
3231
"ms-azuretools.vscode-docker",
3332
"akino.i18n-gettext",
3433
"github.vscode-github-actions"

api/config/delete.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package config
2+
3+
import (
4+
"net/http"
5+
"os"
6+
7+
"github.com/0xJacky/Nginx-UI/internal/config"
8+
"github.com/0xJacky/Nginx-UI/internal/helper"
9+
"github.com/0xJacky/Nginx-UI/internal/nginx"
10+
"github.com/gin-gonic/gin"
11+
"github.com/uozi-tech/cosy"
12+
)
13+
14+
// DeleteConfig handles the deletion of configuration files or directories
15+
func DeleteConfig(c *gin.Context) {
16+
var json struct {
17+
BasePath string `json:"base_path"`
18+
Name string `json:"name" binding:"required"`
19+
SyncNodeIds []uint64 `json:"sync_node_ids" gorm:"serializer:json"`
20+
}
21+
if !cosy.BindAndValid(c, &json) {
22+
return
23+
}
24+
25+
// Decode paths from URL encoding
26+
decodedBasePath := helper.UnescapeURL(json.BasePath)
27+
decodedName := helper.UnescapeURL(json.Name)
28+
29+
fullPath := nginx.GetConfPath(decodedBasePath, decodedName)
30+
31+
// Check if path is under nginx config directory
32+
if err := config.ValidateDeletePath(fullPath); err != nil {
33+
cosy.ErrHandler(c, err)
34+
return
35+
}
36+
37+
// Check if trying to delete protected paths
38+
if config.IsProtectedPath(fullPath, decodedName) {
39+
cosy.ErrHandler(c, config.ErrCannotDeleteProtectedPath)
40+
return
41+
}
42+
43+
// Check if file/directory exists
44+
stat, err := config.CheckFileExists(fullPath)
45+
if err != nil {
46+
cosy.ErrHandler(c, err)
47+
return
48+
}
49+
50+
// Delete the file or directory
51+
err = os.RemoveAll(fullPath)
52+
if err != nil {
53+
cosy.ErrHandler(c, err)
54+
return
55+
}
56+
57+
// Clean up database records
58+
if err := config.CleanupDatabaseRecords(fullPath, stat.IsDir()); err != nil {
59+
cosy.ErrHandler(c, err)
60+
return
61+
}
62+
63+
// Sync deletion to remote servers if configured
64+
if len(json.SyncNodeIds) > 0 {
65+
err = config.SyncDeleteOnRemoteServer(fullPath, json.SyncNodeIds)
66+
if err != nil {
67+
cosy.ErrHandler(c, err)
68+
return
69+
}
70+
}
71+
72+
c.JSON(http.StatusOK, gin.H{
73+
"message": "deleted successfully",
74+
})
75+
}

api/config/router.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func InitRouter(r *gin.RouterGroup) {
1717
{
1818
o.POST("config_mkdir", Mkdir)
1919
o.POST("config_rename", Rename)
20+
o.POST("config_delete", DeleteConfig)
2021
}
2122

2223
r.GET("config_histories", GetConfigHistory)

app/src/api/config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ const config = extendCurdApi(useCurdApi<Config>('/configs'), {
3434
new_name: newName,
3535
sync_node_ids: syncNodeIds,
3636
}),
37+
delete: (basePath: string, name: string, syncNodeIds?: number[]) => http.post('/config_delete', {
38+
base_path: basePath,
39+
name,
40+
sync_node_ids: syncNodeIds,
41+
}),
3742
get_history: (filepath: string, params?: { page: number, page_size: number }) => {
3843
return http.get<GetListResponse<ConfigBackup>>('/config_histories', { params: { filepath, ...params } })
3944
},

0 commit comments

Comments
 (0)