mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 02:15:48 +02:00
feat: mcp server
This commit is contained in:
parent
c4a9d03bb3
commit
e8ee931e16
51 changed files with 2749 additions and 1526 deletions
|
@ -7,10 +7,8 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/0xJacky/Nginx-UI/internal/config"
|
||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/uozi-tech/cosy"
|
||||
"github.com/uozi-tech/cosy/logger"
|
||||
)
|
||||
|
||||
func GetConfigs(c *gin.Context) {
|
||||
|
@ -43,55 +41,14 @@ func GetConfigs(c *gin.Context) {
|
|||
dir = strings.TrimSuffix(dir, "/")
|
||||
}
|
||||
|
||||
configFiles, err := os.ReadDir(nginx.GetConfPath(dir))
|
||||
configs, err := config.GetConfigList(dir, func(file os.FileInfo) bool {
|
||||
return name == "" || strings.Contains(file.Name(), name)
|
||||
})
|
||||
if err != nil {
|
||||
cosy.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
configs := make([]config.Config, 0)
|
||||
|
||||
for i := range configFiles {
|
||||
file := configFiles[i]
|
||||
fileInfo, _ := file.Info()
|
||||
|
||||
if name != "" && !strings.Contains(file.Name(), name) {
|
||||
continue
|
||||
}
|
||||
|
||||
switch mode := fileInfo.Mode(); {
|
||||
case mode.IsRegular(): // regular file, not a hidden file
|
||||
if "." == file.Name()[0:1] {
|
||||
continue
|
||||
}
|
||||
case mode&os.ModeSymlink != 0: // is a symbol
|
||||
var targetPath string
|
||||
targetPath, err = os.Readlink(nginx.GetConfPath(dir, file.Name()))
|
||||
if err != nil {
|
||||
logger.Error("Read Symlink Error", targetPath, err)
|
||||
continue
|
||||
}
|
||||
|
||||
var targetInfo os.FileInfo
|
||||
targetInfo, err = os.Stat(targetPath)
|
||||
if err != nil {
|
||||
logger.Error("Stat Error", targetPath, err)
|
||||
continue
|
||||
}
|
||||
// hide the file if it's target file is a directory
|
||||
if targetInfo.IsDir() {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
configs = append(configs, config.Config{
|
||||
Name: file.Name(),
|
||||
ModifiedAt: fileInfo.ModTime(),
|
||||
Size: fileInfo.Size(),
|
||||
IsDir: fileInfo.IsDir(),
|
||||
})
|
||||
}
|
||||
|
||||
configs = config.Sort(sortBy, order, configs)
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue