mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 18:35:51 +02:00
fix: symbol links are not displayed in config list #272
This commit is contained in:
parent
371472e67b
commit
abe43c5c4d
3 changed files with 74 additions and 74 deletions
|
@ -1,51 +1,52 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/0xJacky/Nginx-UI/api"
|
"github.com/0xJacky/Nginx-UI/api"
|
||||||
"github.com/0xJacky/Nginx-UI/internal/config"
|
"github.com/0xJacky/Nginx-UI/internal/config"
|
||||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||||
"github.com/0xJacky/Nginx-UI/query"
|
"github.com/0xJacky/Nginx-UI/query"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/sashabaranov/go-openai"
|
"github.com/sashabaranov/go-openai"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetConfig(c *gin.Context) {
|
func GetConfig(c *gin.Context) {
|
||||||
name := c.Param("name")
|
name := c.Param("name")
|
||||||
path := nginx.GetConfPath("/", name)
|
|
||||||
|
|
||||||
stat, err := os.Stat(path)
|
path := nginx.GetConfPath("/", name)
|
||||||
|
|
||||||
if err != nil {
|
stat, err := os.Stat(path)
|
||||||
api.ErrHandler(c, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
content, err := os.ReadFile(path)
|
if err != nil {
|
||||||
|
api.ErrHandler(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
content, err := os.ReadFile(path)
|
||||||
api.ErrHandler(c, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
g := query.ChatGPTLog
|
if err != nil {
|
||||||
chatgpt, err := g.Where(g.Name.Eq(path)).FirstOrCreate()
|
api.ErrHandler(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
g := query.ChatGPTLog
|
||||||
api.ErrHandler(c, err)
|
chatgpt, err := g.Where(g.Name.Eq(path)).FirstOrCreate()
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if chatgpt.Content == nil {
|
if err != nil {
|
||||||
chatgpt.Content = make([]openai.ChatCompletionMessage, 0)
|
api.ErrHandler(c, err)
|
||||||
}
|
return
|
||||||
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, config.Config{
|
if chatgpt.Content == nil {
|
||||||
Name: name,
|
chatgpt.Content = make([]openai.ChatCompletionMessage, 0)
|
||||||
Content: string(content),
|
}
|
||||||
ChatGPTMessages: chatgpt.Content,
|
|
||||||
FilePath: path,
|
c.JSON(http.StatusOK, config.Config{
|
||||||
ModifiedAt: stat.ModTime(),
|
Name: name,
|
||||||
})
|
Content: string(content),
|
||||||
|
ChatGPTMessages: chatgpt.Content,
|
||||||
|
FilePath: path,
|
||||||
|
ModifiedAt: stat.ModTime(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ func GetConfigs(c *gin.Context) {
|
||||||
}
|
}
|
||||||
case mode&os.ModeSymlink != 0: // is a symbol
|
case mode&os.ModeSymlink != 0: // is a symbol
|
||||||
var targetPath string
|
var targetPath string
|
||||||
targetPath, err = os.Readlink(nginx.GetConfPath(file.Name()))
|
targetPath, err = os.Readlink(nginx.GetConfPath(dir, file.Name()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("Read Symlink Error", targetPath, err)
|
logger.Error("Read Symlink Error", targetPath, err)
|
||||||
continue
|
continue
|
||||||
|
@ -47,7 +47,7 @@ func GetConfigs(c *gin.Context) {
|
||||||
logger.Error("Stat Error", targetPath, err)
|
logger.Error("Stat Error", targetPath, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// but target file is not a dir
|
// hide the file if it's target file is a directory
|
||||||
if targetInfo.IsDir() {
|
if targetInfo.IsDir() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,51 +1,50 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/0xJacky/Nginx-UI/api"
|
"github.com/0xJacky/Nginx-UI/api"
|
||||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
type EditConfigJson struct {
|
type EditConfigJson struct {
|
||||||
Content string `json:"content" binding:"required"`
|
Content string `json:"content" binding:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func EditConfig(c *gin.Context) {
|
func EditConfig(c *gin.Context) {
|
||||||
name := c.Param("name")
|
name := c.Param("name")
|
||||||
var request EditConfigJson
|
var request EditConfigJson
|
||||||
err := c.BindJSON(&request)
|
err := c.BindJSON(&request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
api.ErrHandler(c, err)
|
api.ErrHandler(c, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
path := nginx.GetConfPath("/", name)
|
path := nginx.GetConfPath("/", name)
|
||||||
content := request.Content
|
content := request.Content
|
||||||
|
|
||||||
origContent, err := os.ReadFile(path)
|
origContent, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
api.ErrHandler(c, err)
|
api.ErrHandler(c, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if content != "" && content != string(origContent) {
|
if content != "" && content != string(origContent) {
|
||||||
// model.CreateBackup(path)
|
err = os.WriteFile(path, []byte(content), 0644)
|
||||||
err = os.WriteFile(path, []byte(content), 0644)
|
if err != nil {
|
||||||
if err != nil {
|
api.ErrHandler(c, err)
|
||||||
api.ErrHandler(c, err)
|
return
|
||||||
return
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
output := nginx.Reload()
|
output := nginx.Reload()
|
||||||
|
|
||||||
if nginx.GetLogLevel(output) >= nginx.Warn {
|
if nginx.GetLogLevel(output) >= nginx.Warn {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
"message": output,
|
"message": output,
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
GetConfig(c)
|
GetConfig(c)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue